chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus: fix rewind logic
[elogind.git]
/
src
/
libsystemd-bus
/
bus-message.c
diff --git
a/src/libsystemd-bus/bus-message.c
b/src/libsystemd-bus/bus-message.c
index b86ef96f83965649f313a6761eecc828509c82d0..8d449c547827581950825a93c07dd6fa14e9c9bc 100644
(file)
--- a/
src/libsystemd-bus/bus-message.c
+++ b/
src/libsystemd-bus/bus-message.c
@@
-791,7
+791,9
@@
_public_ sd_bus_message* sd_bus_message_ref(sd_bus_message *m) {
}
_public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
}
_public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
- assert_return(m, NULL);
+
+ if (!m)
+ return NULL;
assert(m->n_ref > 0);
m->n_ref--;
assert(m->n_ref > 0);
m->n_ref--;
@@
-1894,9
+1896,7
@@
_public_ int sd_bus_message_open_container(
}
static size_t determine_word_size(size_t sz, size_t extra) {
}
static size_t determine_word_size(size_t sz, size_t extra) {
- if (sz <= 0 && extra == 0)
- return 0;
- else if (sz + extra <= 0xFF)
+ if (sz + extra <= 0xFF)
return 1;
else if (sz + extra*2 <= 0xFFFF)
return 2;
return 1;
else if (sz + extra*2 <= 0xFFFF)
return 2;
@@
-2404,10
+2404,12
@@
_public_ int sd_bus_message_append_array_space(
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
assert_return(m, -EINVAL);
assert_return(!m->sealed, -EPERM);
- assert_return(bus_type_is_trivial(type), -EINVAL);
+ assert_return(bus_type_is_trivial(type)
&& type != SD_BUS_TYPE_BOOLEAN
, -EINVAL);
assert_return(ptr || size == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
assert_return(ptr || size == 0, -EINVAL);
assert_return(!m->poisoned, -ESTALE);
+ /* alignment and size of the trivial types (except bool) is
+ * identical for gvariant and dbus1 marshalling */
align = bus_type_get_alignment(type);
sz = bus_type_get_size(type);
align = bus_type_get_alignment(type);
sz = bus_type_get_size(type);
@@
-2554,8
+2556,8
@@
_public_ int sd_bus_message_append_array_memfd(sd_bus_message *m,
part->size = size;
copy_fd = -1;
part->size = size;
copy_fd = -1;
- message_extend_containers(m, size);
m->header->body_size += size;
m->header->body_size += size;
+ message_extend_containers(m, size);
return sd_bus_message_close_container(m);
}
return sd_bus_message_close_container(m);
}
@@
-2693,7
+2695,7
@@
static int bus_message_close_header(sd_bus_message *m) {
return 0;
}
return 0;
}
-int bus_message_seal(sd_bus_message *m, uint64_t serial) {
+int bus_message_seal(sd_bus_message *m, uint64_t serial
, usec_t timeout
) {
struct bus_body_part *part;
size_t l, a;
unsigned i;
struct bus_body_part *part;
size_t l, a;
unsigned i;
@@
-2740,6
+2742,7
@@
int bus_message_seal(sd_bus_message *m, uint64_t serial) {
return r;
m->header->serial = serial;
return r;
m->header->serial = serial;
+ m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout;
/* Add padding at the end of the fields part, since we know
* the body needs to start at an 8 byte alignment. We made
/* Add padding at the end of the fields part, since we know
* the body needs to start at an 8 byte alignment. We made
@@
-2969,8
+2972,12
@@
static int container_next_item(sd_bus_message *m, struct bus_container *c, size_
*rindex = ALIGN_TO(c->offsets[c->offset_index], alignment);
c->item_size = c->offsets[c->offset_index+1] - *rindex;
} else {
*rindex = ALIGN_TO(c->offsets[c->offset_index], alignment);
c->item_size = c->offsets[c->offset_index+1] - *rindex;
} else {
+
+ if (c->offset_index+1 >= (c->end-c->begin)/sz)
+ goto end;
+
/* Fixed-size array */
/* Fixed-size array */
- *rindex
+=
sz;
+ *rindex
= c->begin + (c->offset_index+1) *
sz;
c->item_size = sz;
}
c->item_size = sz;
}
@@
-3057,7
+3064,7
@@
static int message_peek_body(
}
part = find_part(m, start, nbytes, (void**) &q);
}
part = find_part(m, start, nbytes, (void**) &q);
- if (!part ||
!q
)
+ if (!part ||
(nbytes > 0 && !q)
)
return -EBADMSG;
*rindex = end;
return -EBADMSG;
*rindex = end;
@@
-3905,6
+3912,7
@@
_public_ int sd_bus_message_enter_container(sd_bus_message *m,
_public_ int sd_bus_message_exit_container(sd_bus_message *m) {
struct bus_container *c;
_public_ int sd_bus_message_exit_container(sd_bus_message *m) {
struct bus_container *c;
+ unsigned saved;
int r;
assert_return(m, -EINVAL);
int r;
assert_return(m, -EINVAL);
@@
-3936,7
+3944,10
@@
_public_ int sd_bus_message_exit_container(sd_bus_message *m) {
c = message_get_container(m);
c = message_get_container(m);
+ saved = c->index;
+ c->index = c->saved_index;
r = container_next_item(m, c, &m->rindex);
r = container_next_item(m, c, &m->rindex);
+ c->index = saved;
if (r < 0)
return r;
if (r < 0)
return r;
@@
-4140,6
+4151,9
@@
_public_ int sd_bus_message_rewind(sd_bus_message *m, int complete) {
m->rindex = c->begin;
}
m->rindex = c->begin;
}
+ c->offset_index = 0;
+ c->item_size = (c->n_offsets > 0 ? c->offsets[0] : c->end) - c->begin;
+
return !isempty(c->signature);
}
return !isempty(c->signature);
}
@@
-4838,7
+4852,7
@@
int bus_message_parse_fields(sd_bus_message *m) {
uint32_t unix_fds = 0;
void *offsets = NULL;
unsigned n_offsets = 0;
uint32_t unix_fds = 0;
void *offsets = NULL;
unsigned n_offsets = 0;
- size_t sz;
+ size_t sz
= 0
;
unsigned i = 0;
assert(m);
unsigned i = 0;
assert(m);
@@
-5072,9
+5086,6
@@
int bus_message_parse_fields(sd_bus_message *m) {
if (m->n_fds != unix_fds)
return -EBADMSG;
if (m->n_fds != unix_fds)
return -EBADMSG;
- if (isempty(m->root_container.signature) != (BUS_MESSAGE_BODY_SIZE(m) == 0))
- return -EBADMSG;
-
switch (m->header->type) {
case SD_BUS_MESSAGE_SIGNAL:
switch (m->header->type) {
case SD_BUS_MESSAGE_SIGNAL: