chiark / gitweb /
bus: handle serialization of NULL strings
authorLennart Poettering <lennart@poettering.net>
Wed, 6 Nov 2013 01:01:43 +0000 (02:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 6 Nov 2013 01:31:35 +0000 (02:31 +0100)
Instead of simply crashing be somewhat nicer and serialize a NULL string
into the empty string and generate an error on signature and object path
strings.

src/libsystemd-bus/bus-message.c

index e68b43bbae8ef1a21ae6b6cbfdb025fb4a05ff05..437f6dfd49d89840e1fbe716d7409eb0e7afeac0 100644 (file)
@@ -1347,14 +1347,29 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         switch (type) {
 
         case SD_BUS_TYPE_STRING:
         switch (type) {
 
         case SD_BUS_TYPE_STRING:
+                /* To make things easy we'll serialize a NULL string
+                 * into the empty string */
+                p = strempty(p);
+
+                /* Fall through... */
         case SD_BUS_TYPE_OBJECT_PATH:
 
         case SD_BUS_TYPE_OBJECT_PATH:
 
+                if (!p) {
+                        r = -EINVAL;
+                        goto fail;
+                }
+
                 align = 4;
                 sz = 4 + strlen(p) + 1;
                 break;
 
         case SD_BUS_TYPE_SIGNATURE:
 
                 align = 4;
                 sz = 4 + strlen(p) + 1;
                 break;
 
         case SD_BUS_TYPE_SIGNATURE:
 
+                if (!p) {
+                        r = -EINVAL;
+                        goto fail;
+                }
+
                 align = 1;
                 sz = 1 + strlen(p) + 1;
                 break;
                 align = 1;
                 sz = 1 + strlen(p) + 1;
                 break;