A modelling and serializer library for Microsoft Azure IoTHub client applications

Dependents:   sht15_remote_monitoring f767zi_mqtt remote_monitoring simplesample_amqp ... more

This library implements a serializer library to be used in projects involving Microsoft Azure IoT Hub connectivity. The code is replicated from https://github.com/Azure/azure-iot-sdks

Revision:
36:7d12a5386197
Parent:
31:bdcce611d29b
--- a/multitree.c	Thu Jul 12 18:10:30 2018 -0700
+++ b/multitree.c	Tue Sep 11 11:14:37 2018 -0700
@@ -94,7 +94,7 @@
 }CREATELEAF_RESULT;
 
 static STATIC_VAR_UNUSED const char* CreateLeaf_ResultAsString[CREATELEAF_RESULT_COUNT] =
-{   
+{
     TOSTRING(CREATELEAF_OK),
     TOSTRING(CREATELEAF_ALREADY_EXISTS),
     TOSTRING(CREATELEAF_EMPTY_NAME),
@@ -167,7 +167,7 @@
                     /*all is fine until now*/
                 }
             }
-            
+
 
             if (newNode!=NULL)
             {
@@ -216,7 +216,7 @@
     {
         result = MULTITREE_INVALID_ARG;
         LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
-    } 
+    }
     /*Codes_SRS_MULTITREE_99_019:[ If parameter destinationPath is NULL, MULTITREE_INVALID_ARG shall be returned.]*/
     else if (destinationPath == NULL)
     {
@@ -289,14 +289,21 @@
             /*if there's more or 1 delimiter in the path... */
             /*Codes_SRS_MULTITREE_99_017:[ Subsequent names designate hierarchical children in the tree. The last child designates the child that will receive the value.]*/
             char firstInnerNodeName[INNER_NODE_NAME_SIZE];
-            if (strncpy_s(firstInnerNodeName, INNER_NODE_NAME_SIZE, destinationPath, whereIsDelimiter - destinationPath) != 0)
+            if ((whereIsDelimiter - destinationPath) >= INNER_NODE_NAME_SIZE)
             {
                 /*Codes_SRS_MULTITREE_99_025:[ The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/
                 result = MULTITREE_ERROR;
-                LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
+                LogError("Destination path is too large %d", whereIsDelimiter - destinationPath);
+            }
+            else if (memcpy(firstInnerNodeName, destinationPath, whereIsDelimiter - destinationPath) == NULL)
+            {
+                /*Codes_SRS_MULTITREE_99_025:[ The function shall return MULTITREE_ERROR to indicate any other error not specified here.]*/
+                result = MULTITREE_ERROR;
+                LogError("(result = MULTITREE_ERROR)");
             }
             else
             {
+                firstInnerNodeName[whereIsDelimiter - destinationPath] = 0;
                 MULTITREE_HANDLE_DATA *child = getChildByName(node, firstInnerNodeName);
                 if (child == NULL)
                 {
@@ -396,13 +403,13 @@
     MULTITREE_RESULT result;
     /*Codes_SRS_MULTITREE_99_027:[If treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/
     if (treeHandle == NULL)
-    { 
+    {
         result = MULTITREE_INVALID_ARG;
         LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
     }
     /*Codes_SRS_MULTITREE_99_028:[ If parameter count is NULL, the function returns MULTITREE_INVALID_ARG.]*/
     else if (count == NULL)
-    { 
+    {
         result = MULTITREE_INVALID_ARG;
         LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
     }
@@ -431,7 +438,7 @@
         result = MULTITREE_INVALID_ARG;
         LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
     }
-    else 
+    else
     {
         MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle;
         /*Codes_SRS_MULTITREE_99_032:[If parameter index is out of range, the function shall return MULTITREE_OUT_OF_RANGE_INDEX]*/
@@ -760,7 +767,7 @@
                     LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result));
                 }
                 /*Codes_SRS_MULTITREE_99_053:[ MultiTree_GetLeafValue shall copy into the *destination argument the value of the node identified by the leafPath argument.]*/
-                else 
+                else
                 {
                     *destination = node->value;
                     /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_GetLeafValue shall return MULTITREE_OK.] */