summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-10-22 12:40:39 +0100
committerLennart Poettering <lennart@poettering.net>2013-10-22 12:41:54 +0100
commit430fb8fab261e9661ccf3109b0a92cc9a34801b3 (patch)
tree18d9c5c87184a29014ebd168de9b384c674e2fbf /src
parent8d451309667578d3a03cdfc91d6e339fb9fe64a7 (diff)
bus: only if the user tries to read over the end of an array we should handle this as EOF
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-bus/bus-message.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index cfc45a3f71..b0d4dd2158 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -2657,7 +2657,7 @@ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
c = message_get_container(m);
if (!c->signature || c->signature[c->index] == 0)
- return 0;
+ return -ENXIO;
if (message_end_of_array(m, m->rindex))
return 0;
@@ -3008,7 +3008,7 @@ int sd_bus_message_enter_container(sd_bus_message *m, char type, const char *con
c = message_get_container(m);
if (!c->signature || c->signature[c->index] == 0)
- return 0;
+ return -ENXIO;
if (message_end_of_array(m, m->rindex))
return 0;
@@ -3252,11 +3252,12 @@ static int message_read_ap(
unsigned n_array, n_struct;
TypeStack stack[BUS_CONTAINER_DEPTH];
unsigned stack_ptr = 0;
+ unsigned n_loop = 0;
int r;
assert(m);
- if (!types)
+ if (isempty(types))
return 0;
/* Ideally, we'd just call ourselves recursively on every
@@ -3266,12 +3267,14 @@ static int message_read_ap(
* in a single stackframe. We hence implement our own
* home-grown stack in an array. */
- n_array = (unsigned) -1;
- n_struct = strlen(types);
+ n_array = (unsigned) -1; /* lenght of current array entries */
+ n_struct = strlen(types); /* length of current struct contents signature */
for (;;) {
const char *t;
+ n_loop++;
+
if (n_array == 0 || (n_array == (unsigned) -1 && n_struct == 0)) {
r = type_stack_pop(stack, ELEMENTSOF(stack), &stack_ptr, &types, &n_struct, &n_array);
if (r < 0)
@@ -3315,8 +3318,13 @@ static int message_read_ap(
r = sd_bus_message_read_basic(m, *t, p);
if (r < 0)
return r;
- if (r == 0)
+
+ if (r == 0) {
+ if (n_loop <= 1)
+ return 0;
+
return -ENXIO;
+ }
break;
}
@@ -3336,8 +3344,12 @@ static int message_read_ap(
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, s);
if (r < 0)
return r;
- if (r == 0)
+ if (r == 0) {
+ if (n_loop <= 1)
+ return 0;
+
return -ENXIO;
+ }
}
if (n_array == (unsigned) -1) {
@@ -3366,8 +3378,12 @@ static int message_read_ap(
r = sd_bus_message_enter_container(m, SD_BUS_TYPE_VARIANT, s);
if (r < 0)
return r;
- if (r == 0)
+ if (r == 0) {
+ if (n_loop <= 1)
+ return 0;
+
return -ENXIO;
+ }
r = type_stack_push(stack, ELEMENTSOF(stack), &stack_ptr, types, n_struct, n_array);
if (r < 0)
@@ -3396,8 +3412,11 @@ static int message_read_ap(
r = sd_bus_message_enter_container(m, *t == SD_BUS_TYPE_STRUCT_BEGIN ? SD_BUS_TYPE_STRUCT : SD_BUS_TYPE_DICT_ENTRY, s);
if (r < 0)
return r;
- if (r == 0)
+ if (r == 0) {
+ if (n_loop <= 1)
+ return 0;
return -ENXIO;
+ }
}
if (n_array == (unsigned) -1) {