1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-04 21:47:31 +03:00

bus: generate a nice error when attempting to add a NULL string

This commit is contained in:
Lennart Poettering 2013-03-22 00:24:21 +01:00
parent b9bf7e2be9
commit b8beb27816
3 changed files with 19 additions and 1 deletions

View File

@ -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;

View File

@ -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

View File

@ -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);