Merge "Mobicore: Update internally managed branch"
diff --git a/MobiCoreDriverLib/ClientLib/GP/tee_client_api.cpp b/MobiCoreDriverLib/ClientLib/GP/tee_client_api.cpp
index e86fa97..e9e53bc 100755
--- a/MobiCoreDriverLib/ClientLib/GP/tee_client_api.cpp
+++ b/MobiCoreDriverLib/ClientLib/GP/tee_client_api.cpp
@@ -238,7 +238,7 @@
 
     // Fill in invalid values for secure world to overwrite
     tci->returnStatus = 0;
-    tci->returnStatus = TEE_ERROR_BAD_STATE;
+    tci->returnStatus = TEEC_ERROR_BAD_STATE;
 
     // Signal completion of request writing
     tci->ready = 1;
@@ -442,7 +442,7 @@
                 LOG_E("Target is DEAD");
 
                 *returnOrigin = TEEC_ORIGIN_TEE;
-                teecError = TEE_ERROR_TARGET_DEAD;
+                teecError = TEEC_ERROR_TARGET_DEAD;
             }
         }
     }
diff --git a/MobiCoreDriverLib/ClientLib/public/GP/tee_error.h b/MobiCoreDriverLib/ClientLib/public/GP/tee_error.h
index 79d99e8..e90786a 100755
--- a/MobiCoreDriverLib/ClientLib/public/GP/tee_error.h
+++ b/MobiCoreDriverLib/ClientLib/public/GP/tee_error.h
@@ -1,4 +1,4 @@
- /*
+/*
  * Copyright (c) 2013 TRUSTONIC LIMITED
  * All rights reserved.
  *
@@ -32,166 +32,100 @@
 #ifndef __TEE_ERROR_H__
 #define __TEE_ERROR_H__
 
-#define TEE_SUCCESS                      ((TEE_Result)0x00000000)
-#define TEEC_SUCCESS                   TEE_SUCCESS
-
-#define TEE_ERROR_CORRUPT_OBJECT         ((TEE_Result)0xF0100001)
-#define TEE_ERROR_CORRUPT_OBJECT_2       ((TEE_Result)0xF0100002)
+#define TEEC_SUCCESS                      ((TEEC_Result)0x00000000)
 
 /**
  * Generic error code : Generic error
  **/
-#define TEE_ERROR_GENERIC                ((TEE_Result)0xFFFF0000)
-#define TEEC_ERROR_GENERIC             TEE_ERROR_GENERIC
+#define TEEC_ERROR_GENERIC                ((TEEC_Result)0xFFFF0000)
 
 /**
  * Generic error code : The underlying security system denies the access to the
  * object
  **/
-#define TEE_ERROR_ACCESS_DENIED          ((TEE_Result)0xFFFF0001)
-#define TEEC_ERROR_ACCESS_DENIED       TEE_ERROR_ACCESS_DENIED
+#define TEEC_ERROR_ACCESS_DENIED          ((TEEC_Result)0xFFFF0001)
 
 /**
  * Generic error code : The pending operation is cancelled.
  **/
-#define TEE_ERROR_CANCEL                 ((TEE_Result)0xFFFF0002)
-#define TEEC_ERROR_CANCEL              TEE_ERROR_CANCEL
+#define TEEC_ERROR_CANCEL                 ((TEEC_Result)0xFFFF0002)
 
 /**
  * Generic error code : The underlying system detects a conflict
  **/
-#define TEE_ERROR_ACCESS_CONFLICT        ((TEE_Result)0xFFFF0003)
-#define TEEC_ERROR_ACCESS_CONFLICT     TEE_ERROR_ACCESS_CONFLICT
+#define TEEC_ERROR_ACCESS_CONFLICT        ((TEEC_Result)0xFFFF0003)
 
 /**
  * Generic error code : Too much data for the operation or some data remain
  * unprocessed by the operation.
  **/
-#define TEE_ERROR_EXCESS_DATA            ((TEE_Result)0xFFFF0004)
-#define TEEC_ERROR_EXCESS_DATA         TEE_ERROR_EXCESS_DATA
+#define TEEC_ERROR_EXCESS_DATA            ((TEEC_Result)0xFFFF0004)
 
 /**
  * Generic error code : Error of data format
  **/
-#define TEE_ERROR_BAD_FORMAT             ((TEE_Result)0xFFFF0005)
-#define TEEC_ERROR_BAD_FORMAT          TEE_ERROR_BAD_FORMAT
+#define TEEC_ERROR_BAD_FORMAT             ((TEEC_Result)0xFFFF0005)
 
 /**
  * Generic error code : The specified parameters are invalid
  **/
-#define TEE_ERROR_BAD_PARAMETERS         ((TEE_Result)0xFFFF0006)
-#define TEEC_ERROR_BAD_PARAMETERS      TEE_ERROR_BAD_PARAMETERS
-
+#define TEEC_ERROR_BAD_PARAMETERS         ((TEEC_Result)0xFFFF0006)
 
 /**
  * Generic error code : Illegal state for the operation.
  **/
-#define TEE_ERROR_BAD_STATE              ((TEE_Result)0xFFFF0007)
-#define TEEC_ERROR_BAD_STATE           TEE_ERROR_BAD_STATE
+#define TEEC_ERROR_BAD_STATE              ((TEEC_Result)0xFFFF0007)
 
 /**
  * Generic error code : The item is not found
  **/
-#define TEE_ERROR_ITEM_NOT_FOUND         ((TEE_Result)0xFFFF0008)
-#define TEEC_ERROR_ITEM_NOT_FOUND      TEE_ERROR_ITEM_NOT_FOUND
+#define TEEC_ERROR_ITEM_NOT_FOUND         ((TEEC_Result)0xFFFF0008)
 
 /**
  * Generic error code : The specified operation is not implemented
  **/
-#define TEE_ERROR_NOT_IMPLEMENTED        ((TEE_Result)0xFFFF0009)
-#define TEEC_ERROR_NOT_IMPLEMENTED     TEE_ERROR_NOT_IMPLEMENTED
+#define TEEC_ERROR_NOT_IMPLEMENTED        ((TEEC_Result)0xFFFF0009)
 
 /**
  * Generic error code : The specified operation is not supported
  **/
-#define TEE_ERROR_NOT_SUPPORTED          ((TEE_Result)0xFFFF000A)
-#define TEEC_ERROR_NOT_SUPPORTED       TEE_ERROR_NOT_SUPPORTED
+#define TEEC_ERROR_NOT_SUPPORTED          ((TEEC_Result)0xFFFF000A)
 
 /**
  * Generic error code : Insufficient data is available for the operation.
  **/
-#define TEE_ERROR_NO_DATA                ((TEE_Result)0xFFFF000B)
-#define TEEC_ERROR_NO_DATA             TEE_ERROR_NO_DATA
+#define TEEC_ERROR_NO_DATA                ((TEEC_Result)0xFFFF000B)
 
 /**
  * Generic error code : Not enough memory to perform the operation
  **/
-#define TEE_ERROR_OUT_OF_MEMORY          ((TEE_Result)0xFFFF000C)
-#define TEEC_ERROR_OUT_OF_MEMORY       TEE_ERROR_OUT_OF_MEMORY
+#define TEEC_ERROR_OUT_OF_MEMORY          ((TEEC_Result)0xFFFF000C)
 
 /**
  * Generic error code : The service is currently unable to handle the request;
  * try later
  **/
-#define TEE_ERROR_BUSY                   ((TEE_Result)0xFFFF000D)
-#define TEEC_ERROR_BUSY                TEE_ERROR_BUSY
+#define TEEC_ERROR_BUSY                   ((TEEC_Result)0xFFFF000D)
 
 /**
  * Generic communication error
  **/
-#define TEE_ERROR_COMMUNICATION          ((TEE_Result)0xFFFF000E)
-#define TEEC_ERROR_COMMUNICATION       TEE_ERROR_COMMUNICATION
+#define TEEC_ERROR_COMMUNICATION          ((TEEC_Result)0xFFFF000E)
 
 /**
  * Generic error code : security violation
  **/
-#define TEE_ERROR_SECURITY               ((TEE_Result)0xFFFF000F)
-#define TEEC_ERROR_SECURITY            TEE_ERROR_SECURITY
+#define TEEC_ERROR_SECURITY               ((TEEC_Result)0xFFFF000F)
 
 /**
  * Generic error code : the buffer is too short
  **/
-#define TEE_ERROR_SHORT_BUFFER           ((TEE_Result)0xFFFF0010)
-#define TEEC_ERROR_SHORT_BUFFER        TEE_ERROR_SHORT_BUFFER
-
-/**
- * Generic error code : The pending operation is cancelled.
- */
-#define TEE_ERROR_EXTERNAL_CANCEL        ((TEE_Result)0xFFFF0011)
-
-/**
- * Generic error code : the operation is not terminated
- **/
-#define TEE_PENDING                      ((TEE_Result)0xFFFF2000)
-
-/**
- * Generic error code : A timeout occurred
- **/
-#define TEE_ERROR_TIMEOUT                ((TEE_Result)0xFFFF3001)
-
-/**
- * Generic error code : Overflow
- **/
-#define TEE_ERROR_OVERFLOW               ((TEE_Result)0xFFFF300F)
+#define TEEC_ERROR_SHORT_BUFFER           ((TEEC_Result)0xFFFF0010)
 
 /**
  * Error of communication: The target of the connection is dead
  **/
-#define TEE_ERROR_TARGET_DEAD            ((TEE_Result)0xFFFF3024)
-#define TEEC_ERROR_TARGET_DEAD         TEE_ERROR_TARGET_DEAD
-
-/*------------------------------------------------------------------------------
-   Storage Error Codes
-------------------------------------------------------------------------------*/
-
-/** File system error code: not enough space to complete the operation. */
-#define TEE_ERROR_STORAGE_NO_SPACE       ((TEE_Result)0xFFFF3041)
-
-/*------------------------------------------------------------------------------
-   Crypto error codes
-------------------------------------------------------------------------------*/
-
-#define TEE_ERROR_MAC_INVALID          ((TEE_Result)0xFFFF3071)
-
-#define TEE_ERROR_SIGNATURE_INVALID    ((TEE_Result)0xFFFF3072)
-
-/*------------------------------------------------------------------------------
-   Date error codes
-------------------------------------------------------------------------------*/
-
-#define TEE_ERROR_TIME_NOT_SET         ((TEE_Result)0xFFFF5000)
-
-#define TEE_ERROR_TIME_NEEDS_RESET     ((TEE_Result)0xFFFF5001)
+#define TEEC_ERROR_TARGET_DEAD            ((TEEC_Result)0xFFFF3024)
 
 #endif /* __TEE_ERROR_H__ */
 
diff --git a/MobiCoreDriverLib/ClientLib/public/GP/tee_type.h b/MobiCoreDriverLib/ClientLib/public/GP/tee_type.h
index 48d7293..f164dab 100755
--- a/MobiCoreDriverLib/ClientLib/public/GP/tee_type.h
+++ b/MobiCoreDriverLib/ClientLib/public/GP/tee_type.h
@@ -28,7 +28,6 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-
 /**
  * Definition of the machine-specific integer types
  **/
@@ -103,15 +102,7 @@
 #define IN
 #define OUT
 
-/*
- * Definition of other common types
- */
-
-// to delete when all completed
-typedef uint32_t TEE_Result;
-typedef TEE_Result TEEC_Result;
-
-typedef uint32_t TEE_HANDLE;
+typedef uint32_t TEEC_Result;
 
 /** Definition of an UUID (from RFC 4122 http://www.ietf.org/rfc/rfc4122.txt) */
 typedef struct TEE_UUID {
@@ -122,42 +113,4 @@
 } TEE_UUID;
 typedef TEE_UUID TEEC_UUID;
 
-/** Type definition for a TEE Identity */
-typedef struct TEE_Identity {
-    uint32_t login;
-    TEE_UUID uuid;
-} TEE_Identity;
-
-typedef struct __TEE_PropSetHandle {
-    unsigned char reserved;
-} __TEE_PropSetHandle;
-
-typedef struct __TEE_PropSetHandle* TEE_PropSetHandle;
-
-/* Property Sets Pseudo Handles */
-#define TEE_PROPSET_CURRENT_TA               (TEE_PropSetHandle)0xFFFFFFFF
-#define TEE_PROPSET_CURRENT_CLIENT           (TEE_PropSetHandle)0xFFFFFFFE
-#define TEE_PROPSET_TEE_IMPLEMENTATION       (TEE_PropSetHandle)0xFFFFFFFD
-
-
-/* DLL Import/Export directives */
-
-#if defined(WIN32) || defined(__ARMCC_VERSION) || defined(__WINSCW__) || defined(_WIN32_WCE)
-#  define S_DLL_EXPORT __declspec(dllexport)
-#  define S_DLL_IMPORT __declspec(dllimport)
-#  define S_NO_RETURN  __declspec(noreturn)
-#elif defined(__GNUC__)
-#  define S_DLL_EXPORT __attribute__ ((visibility ("default")))
-#  define S_DLL_IMPORT __attribute__ ((visibility ("default")))
-#  define S_NO_RETURN  __attribute__ ((noreturn))
-#else
-#  define S_DLL_EXPORT
-#  define S_DLL_IMPORT
-#  define S_NO_RETURN
-#endif
-
-#if defined(_MSC_VER)
-#define __func__ __FUNCTION__
-#endif
-
 #endif /* __TEE_TYPE_H__ */
diff --git a/MobiCoreDriverLib/ClientLib/public/GP/uuid_attestation.h b/MobiCoreDriverLib/ClientLib/public/GP/uuid_attestation.h
index ea562fd..c16f666 100755
--- a/MobiCoreDriverLib/ClientLib/public/GP/uuid_attestation.h
+++ b/MobiCoreDriverLib/ClientLib/public/GP/uuid_attestation.h
@@ -44,9 +44,9 @@
 #define AT_TAG_SIZE             20
 #define AT_SHA1_HASH_SIZE       20
 
-// Max size of RSA modulus supported 
+// Max size of RSA modulus supported
 #define AT_MODULUS_MAX_SIZE     256
-// Max size of RSA public exponent supported 
+// Max size of RSA public exponent supported
 #define AT_PUBLIC_EXPO_MAX_SIZE 4
 
 // Attestation version
@@ -62,7 +62,7 @@
 
 // Public key structure
 typedef struct uuid_public_key {
-    uint32_t    type;           // TEE TYPE RSA KEYPAIR: 0xa0000030
+    uint32_t    type;           // TEE_TYPE_RSA_PUBLIC_KEY: 0xA0000030
     uint16_t    modulus_bytes;  // Length of the modulus in bytes
     uint16_t    exponent_bytes; // Length of the exponent in bytes
     uint8_t     data[];         // Key material
diff --git a/MobiCoreDriverLib/Daemon/FSD/Android.mk b/MobiCoreDriverLib/Daemon/FSD/Android.mk
index 77f7cd3..144d141 100755
--- a/MobiCoreDriverLib/Daemon/FSD/Android.mk
+++ b/MobiCoreDriverLib/Daemon/FSD/Android.mk
@@ -11,8 +11,7 @@
 
 # Add new folders with header files here
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/$(FSD_PATH)/public \
-                    $(COMP_PATH_DrSecureStorage)/Public \
-                    $(MOBICORE_PROJECT_PATH)/include/GPD_TEE_Internal_API
+                    $(LOCAL_PATH)/ClientLib/public/GP \
 
 # Add new source files here
 LOCAL_SRC_FILES += $(FSD_PATH)/FSD.cpp \
\ No newline at end of file
diff --git a/MobiCoreDriverLib/Daemon/FSD/FSD.cpp b/MobiCoreDriverLib/Daemon/FSD/FSD.cpp
index e1617ba..95ab057 100755
--- a/MobiCoreDriverLib/Daemon/FSD/FSD.cpp
+++ b/MobiCoreDriverLib/Daemon/FSD/FSD.cpp
@@ -45,7 +45,11 @@
 //#define LOG_VERBOSE
 #include "log.h"
 
+/* The following definitions are not exported in the header files of the
+   client API. */
 #define TEE_DATA_FLAG_EXCLUSIVE              0x00000400
+#define TEE_ERROR_STORAGE_NO_SPACE       ((TEEC_Result)0xFFFF3041)
+#define TEE_ERROR_CORRUPT_OBJECT         ((TEEC_Result)0xF0100001)
 
 extern string getTbStoragePath();
 
@@ -355,8 +359,8 @@
 	pFile = fopen(Filepath, "r");
 	if (pFile==NULL)
 	{
-		LOG_E("%s: Error looking for file 0x%.8x\n",__func__,TEE_ERROR_ITEM_NOT_FOUND);
-		return TEE_ERROR_ITEM_NOT_FOUND;
+		LOG_E("%s: Error looking for file 0x%.8x\n",__func__,TEEC_ERROR_ITEM_NOT_FOUND);
+		return TEEC_ERROR_ITEM_NOT_FOUND;
 	}
 
 	res = fread(sth_request->payload,sizeof(char),sth_request->payloadLen,pFile);
@@ -365,9 +369,9 @@
 	if ((uint32_t)res != sth_request->payloadLen)
 	{
 		LOG_E("%s: Error reading file res is %d and errno is %s\n",__func__,res,strerror(errno));
-		return TEE_ERROR_ITEM_NOT_FOUND;
+		return TEEC_ERROR_ITEM_NOT_FOUND;
 	}
-	return TEE_SUCCESS;
+	return TEEC_SUCCESS;
 }
 
 
@@ -402,8 +406,8 @@
 	pFile = fopen(Filepath, "r");
 	if (pFile==NULL)
 	{
-		LOG_E("%s: Error looking for file 0x%.8x\n", __func__,TEE_ERROR_ITEM_NOT_FOUND);
-		return TEE_ERROR_ITEM_NOT_FOUND;
+		LOG_E("%s: Error looking for file 0x%.8x\n", __func__,TEEC_ERROR_ITEM_NOT_FOUND);
+		return TEEC_ERROR_ITEM_NOT_FOUND;
 	}
 	res = fread(sth_request->payload,sizeof(char),sth_request->payloadLen,pFile);
 
@@ -412,9 +416,9 @@
 	if ((uint32_t)res != sth_request->payloadLen)
 	{
 		LOG_E("%s: Error reading file res is %d and errno is %s\n",__func__,res,strerror(errno));
-		return TEE_ERROR_ITEM_NOT_FOUND;
+		return TEEC_ERROR_ITEM_NOT_FOUND;
 	}
-	return TEE_SUCCESS;
+	return TEEC_SUCCESS;
 }
 
 
@@ -497,7 +501,7 @@
 		{
 			LOG_E("%s: remove failed: %s\n",__func__, strerror(errno));
 		}
-		return TEE_ERROR_ITEM_NOT_FOUND;
+		return TEEC_ERROR_ITEM_NOT_FOUND;
 	}
 	else
 	{
@@ -531,7 +535,7 @@
 			return TEE_ERROR_STORAGE_NO_SPACE;
 		}
 	}
-	return TEE_SUCCESS;
+	return TEEC_SUCCESS;
 }
 
 
@@ -571,7 +575,7 @@
 	if (pFile==NULL)
 	{
 		LOG_I("%s: file not found: %s (%s)\n",__func__, Filepath, strerror(errno));
-		ret = TEE_SUCCESS;
+		ret = TEEC_SUCCESS;
 	}
 	else
 	{
@@ -590,7 +594,7 @@
 	}
 	else
 	{
-		ret = TEE_SUCCESS;
+		ret = TEEC_SUCCESS;
 	}
 
 	return ret;
diff --git a/MobiCoreDriverLib/Daemon/FSD/public/drSecureStorage_Api.h b/MobiCoreDriverLib/Daemon/FSD/public/drSecureStorage_Api.h
index 46da5ae..46cc36f 100755
--- a/MobiCoreDriverLib/Daemon/FSD/public/drSecureStorage_Api.h
+++ b/MobiCoreDriverLib/Daemon/FSD/public/drSecureStorage_Api.h
@@ -28,6 +28,7 @@
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+
 /**
  * @file   drSecureStorage_Api.h
  * @brief  Contains DCI command definitions and data structures
diff --git a/MobiCoreDriverLib/buildTag.h b/MobiCoreDriverLib/buildTag.h
index c494a37..bb90ab7 100755
--- a/MobiCoreDriverLib/buildTag.h
+++ b/MobiCoreDriverLib/buildTag.h
@@ -25,4 +25,5 @@
  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-#define MOBICORE_COMPONENT_BUILD_TAG "*** t-base-300-QC-8974-Engineering-V001 ###"
+#define MOBICORE_COMPONENT_BUILD_TAG \
+		"*** t-base-300-QC-8x26-Android-V001 ###"
diff --git a/rootpa/Code/Android/app/jni/CommonPAWrapper/commonwrapper.cpp b/rootpa/Code/Android/app/jni/CommonPAWrapper/commonwrapper.cpp
index 1c6d3a3..a6e5745 100755
--- a/rootpa/Code/Android/app/jni/CommonPAWrapper/commonwrapper.cpp
+++ b/rootpa/Code/Android/app/jni/CommonPAWrapper/commonwrapper.cpp
@@ -468,7 +468,10 @@
     {
         const char* tmp=envP->GetStringUTFChars(source, NULL);
         *target=(char*)malloc(strlen(tmp)+1);
-        strcpy(*target, tmp);
+        if(*target!=NULL)
+        {
+            strcpy(*target, tmp);
+        }
         envP->ReleaseStringUTFChars(source, tmp);
     }
     else
diff --git a/rootpa/Code/Android/app/res/values/version.xml b/rootpa/Code/Android/app/res/values/version.xml
index 054297f..c6bbf5a 100755
--- a/rootpa/Code/Android/app/res/values/version.xml
+++ b/rootpa/Code/Android/app/res/values/version.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-    <string name="name">2.0071 (47817)</string>
-    <integer name="code">0x20047</integer>
+    <string name="name">2.0072 (49652)</string>
+    <integer name="code">0x20048</integer>
 </resources>
diff --git a/rootpa/Code/Common/include/version.h b/rootpa/Code/Common/include/version.h
index 1485d8f..daadce0 100755
--- a/rootpa/Code/Common/include/version.h
+++ b/rootpa/Code/Common/include/version.h
@@ -35,6 +35,6 @@
 #define ROOTPA_VERSION_H_
 
 #define ROOTPA_VERSION_MAJOR 2
-#define ROOTPA_VERSION_MINOR 71
+#define ROOTPA_VERSION_MINOR 72
 
 #endif /** ROOTPA_VERSION_H_ */
diff --git a/rootpa/Code/Common/provisioningengine.c b/rootpa/Code/Common/provisioningengine.c
index f6fd764..54d1b3e 100755
--- a/rootpa/Code/Common/provisioningengine.c
+++ b/rootpa/Code/Common/provisioningengine.c
@@ -154,9 +154,16 @@
     
     urlLength=strlen(initialUrl_) + (sizeof(mcSuid_t)*2) + (sizeof(mcSpid_t)*2) + (sizeof(mcUuid_t)*2)+6; //possible slash and end zero and four dashes
     tmpLinkP=malloc(urlLength);
-    memset(tmpLinkP,0,urlLength);
-    strncpy(tmpLinkP, initialUrl_, urlLength);
-    addBytesToUri(tmpLinkP, (uint8_t*) &suid, sizeof(suid), false);
+    if(tmpLinkP != NULL)
+    {
+        memset(tmpLinkP,0,urlLength);
+        strncpy(tmpLinkP, initialUrl_, urlLength);
+        addBytesToUri(tmpLinkP, (uint8_t*) &suid, sizeof(suid), false);
+    }
+    else
+    {
+        LOGE("createBasicLink, out of memory");        
+    }
     return tmpLinkP;
 }
 
@@ -195,6 +202,11 @@
     }
 
     linkP=createBasicLink(suid);
+    if(NULL==linkP)
+    {
+        callbackP(ERROR, ROOTPA_ERROR_OUT_OF_MEMORY, NULL);
+        return;
+    }
     
     if (initialRel == initialRel_DELETE)
     {
@@ -317,9 +329,16 @@
                 free(osSpecificInfo.hardwareP);
                 free(osSpecificInfo.modelP);
                 free(osSpecificInfo.versionP);
-
-                tmpRet=httpPutAndReceiveCommand(responseP, &linkP, &relP, &commandP);
-                if(tmpRet!=ROOTPA_OK) ret=tmpRet;
+                if(responseP!=NULL)
+                {
+                    tmpRet=httpPutAndReceiveCommand(responseP, &linkP, &relP, &commandP);
+                    if(tmpRet!=ROOTPA_OK) ret=tmpRet;
+                }
+                else if(ROOTPA_OK==ret)
+                {
+                    ret=ROOTPA_ERROR_OUT_OF_MEMORY;
+                }
+                
                 if(ret!=ROOTPA_OK)
                 {
                     LOGE("getSysInfoP, getVersionP or buildXmlSystemInfo or httpPutAndReceiveCommand returned an error %d", ret);
diff --git a/rootpa/Code/Common/seclient.c b/rootpa/Code/Common/seclient.c
index 207cde5..175ef5d 100755
--- a/rootpa/Code/Common/seclient.c
+++ b/rootpa/Code/Common/seclient.c
@@ -178,6 +178,7 @@
     if(debugMessageP!=NULL && debugMessageSize!=0)
     {
         char* msgP=malloc(debugMessageSize+1);
+        if(NULL==msgP)return 0;
         memcpy(msgP, debugMessageP, debugMessageSize);
         msgP[debugMessageSize]=0;
         LOGD("curl: %d %s",info, msgP);
diff --git a/rootpa/Code/Common/xmlmessagehandler.c b/rootpa/Code/Common/xmlmessagehandler.c
index 6f979bc..7915e2d 100755
--- a/rootpa/Code/Common/xmlmessagehandler.c
+++ b/rootpa/Code/Common/xmlmessagehandler.c
@@ -573,7 +573,6 @@
     {
         uint32_t internalError;
         cmpResponsesP=malloc(sizeof(CmpMessage)*numberOfCmpCommands);
-        memset(cmpResponsesP, 0, sizeof(CmpMessage)*numberOfCmpCommands);
 
         if(NULL==cmpResponsesP)
         {
@@ -581,6 +580,7 @@
         }
         else
         {
+            memset(cmpResponsesP, 0, sizeof(CmpMessage)*numberOfCmpCommands);            
             tmpRet=executeContentManagementCommands(numberOfCmpCommands, cmpCommandsP, cmpResponsesP, &internalError);
             if(ROOTPA_OK!=tmpRet)
             {
@@ -736,7 +736,10 @@
         // be on the safe side
 
         dumpedP=malloc(size+1);
-        strncpy((char*) dumpedP, (char*) dumpP, size+1);
+        if(dumpedP!=NULL)
+        {
+            strncpy((char*) dumpedP, (char*) dumpP, size+1);
+        }
         xmlFree(dumpP);
     }
     xmlFreeDoc(xmlResponseP);