SDOCM00105512: Support unnamed Linux MessageQs
authorChris Ring <cring@ti.com>
Fri, 6 Dec 2013 00:52:42 +0000 (16:52 -0800)
committerChris Ring <cring@ti.com>
Fri, 6 Dec 2013 01:01:50 +0000 (17:01 -0800)
The MessageQ API supports unnamed MessageQs; update Linux's
LAD-based MessageQ creation command to handle this.

Previously a segment fault would occur due to strncpy() being
passed a NULL src string array.

linux/src/api/MessageQ.c
linux/src/daemon/lad.c

index c2930ad44c1b351fe4163ef298f93518142f524a..33aaff184cedd17f9ea96a03604bb1227b1cec4c 100644 (file)
@@ -352,9 +352,15 @@ MessageQ_Handle MessageQ_create (String name, const MessageQ_Params * params)
 
     cmd.cmd = LAD_MESSAGEQ_CREATE;
     cmd.clientId = handle;
-    strncpy(cmd.args.messageQCreate.name, name,
-            LAD_MESSAGEQCREATEMAXNAMELEN - 1);
-    cmd.args.messageQCreate.name[LAD_MESSAGEQCREATEMAXNAMELEN - 1] = '\0';
+    if (name == NULL) {
+        cmd.args.messageQCreate.name[0] = '\0';
+    }
+    else {
+        strncpy(cmd.args.messageQCreate.name, name,
+                LAD_MESSAGEQCREATEMAXNAMELEN - 1);
+        cmd.args.messageQCreate.name[LAD_MESSAGEQCREATEMAXNAMELEN - 1] = '\0';
+    }
+
     if (params) {
         memcpy(&cmd.args.messageQCreate.params, params, sizeof(*params));
     }
index c16708288a8c6edee110f5b505512eeb701ae694..a89810099177f77a8baa63625df66708151aa5ed 100644 (file)
@@ -93,6 +93,7 @@ int main(int argc, char * argv[])
     Int flags;
     Int i;
     Int n;
+    String tmpString;
 #if DAEMON
     pid_t pid;
     pid_t sid;
@@ -409,10 +410,14 @@ opencommandFIFO:
             break;
 
           case LAD_MESSAGEQ_CREATE:
-            LOG2("LAD_MESSAGEQ_CREATE: calling MessageQ_create(%p, %p)...\n", cmd.args.messageQCreate.name, &cmd.args.messageQCreate.params)
+            LOG2("LAD_MESSAGEQ_CREATE: calling MessageQ_create(%p, %p)...\n",
+                    cmd.args.messageQCreate.name,
+                    &cmd.args.messageQCreate.params);
 
-            handle = MessageQ_create(cmd.args.messageQCreate.name,
-                &cmd.args.messageQCreate.params);
+            tmpString = (cmd.args.messageQCreate.name[0] == '\0') ? NULL :
+                cmd.args.messageQCreate.name;
+
+            handle = MessageQ_create(tmpString, &cmd.args.messageQCreate.params);
             rsp.messageQCreate.serverHandle = handle;
 
             if (handle) {