summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-03-22 00:24:21 +0100
committerLennart Poettering <lennart@poettering.net>2013-03-22 00:24:21 +0100
commitb8beb2781682738f3a59aab993bf2869447a77c9 (patch)
tree6cebf0391a2558f983a586e4f28c5eea3c99e589 /src
parentb9bf7e2be93fe25e0e96e06ad436d43a1e589ed5 (diff)
bus: generate a nice error when attempting to add a NULL string
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-bus/bus-message.c16
-rw-r--r--src/libsystemd-bus/sd-bus.h1
-rw-r--r--src/libsystemd-bus/test-bus-marshal.c3
3 files changed, 19 insertions, 1 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index c0a0242fd6..524f17eb9f 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -768,11 +768,27 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
case SD_BUS_TYPE_STRING:
case SD_BUS_TYPE_OBJECT_PATH:
+
+ if (!p) {
+ if (e)
+ c->signature[c->index] = 0;
+
+ return -EINVAL;
+ }
+
align = 4;
sz = 4 + strlen(p) + 1;
break;
case SD_BUS_TYPE_SIGNATURE:
+
+ if (!p) {
+ if (e)
+ c->signature[c->index] = 0;
+
+ return -EINVAL;
+ }
+
align = 1;
sz = 1 + strlen(p) + 1;
break;
diff --git a/src/libsystemd-bus/sd-bus.h b/src/libsystemd-bus/sd-bus.h
index d5101c20d7..3ea4acc76f 100644
--- a/src/libsystemd-bus/sd-bus.h
+++ b/src/libsystemd-bus/sd-bus.h
@@ -33,7 +33,6 @@
* - add page donation logic
* - api for appending/reading fixed arrays
* - always verify container depth
- * - handle NULL strings nicer when appending
* - merge busctl into systemctl or so?
* - add object handlers
* - verify object paths
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 15c472cca0..d12c847f35 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -50,6 +50,9 @@ int main(int argc, char *argv[]) {
r = sd_bus_message_append(m, "s", "a string");
assert_se(r >= 0);
+ r = sd_bus_message_append(m, "s", NULL);
+ assert_se(r < 0);
+
r = sd_bus_message_append(m, "as", 2, "string #1", "string #2");
assert_se(r >= 0);