chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
sd-bus: don't choke if somebody sends us a message with a unix fd count of 0
[elogind.git]
/
src
/
libsystemd
/
sd-bus
/
bus-message.c
diff --git
a/src/libsystemd/sd-bus/bus-message.c
b/src/libsystemd/sd-bus/bus-message.c
index 4e95226c5d7b231d516b50369c183d64f3b892cd..b9d7f6dbfd2961fd1e83548b74d1717581413c85 100644
(file)
--- a/
src/libsystemd/sd-bus/bus-message.c
+++ b/
src/libsystemd/sd-bus/bus-message.c
@@
-194,7
+194,7
@@
static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, b
/* Zero out padding */
if (start > old_size)
/* Zero out padding */
if (start > old_size)
- mem
set((uint8_t*) np + old_size, 0
, start - old_size);
+ mem
zero((uint8_t*) np + old_size
, start - old_size);
op = m->header;
m->header = np;
op = m->header;
m->header = np;
@@
-252,7
+252,7
@@
static int message_append_field_string(
return -ENOMEM;
p[0] = h;
return -ENOMEM;
p[0] = h;
- mem
set(p+1, 0
, 7);
+ mem
zero(p+1
, 7);
memcpy(p+8, s, l);
p[8+l] = 0;
p[8+l+1] = 0;
memcpy(p+8, s, l);
p[8+l] = 0;
p[8+l+1] = 0;
@@
-337,7
+337,7
@@
static int message_append_field_uint32(sd_bus_message *m, uint8_t h, uint32_t x)
return -ENOMEM;
p[0] = h;
return -ENOMEM;
p[0] = h;
- mem
set(p+1, 0
, 7);
+ mem
zero(p+1
, 7);
*((uint32_t*) (p + 8)) = x;
p[12] = 0;
p[13] = 'u';
*((uint32_t*) (p + 8)) = x;
p[12] = 0;
p[13] = 'u';
@@
-509,10
+509,10
@@
static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
_public_ int sd_bus_message_new_signal(
sd_bus *bus,
_public_ int sd_bus_message_new_signal(
sd_bus *bus,
+ sd_bus_message **m,
const char *path,
const char *interface,
const char *path,
const char *interface,
- const char *member,
- sd_bus_message **m) {
+ const char *member) {
sd_bus_message *t;
int r;
sd_bus_message *t;
int r;
@@
-549,11
+549,11
@@
fail:
_public_ int sd_bus_message_new_method_call(
sd_bus *bus,
_public_ int sd_bus_message_new_method_call(
sd_bus *bus,
+ sd_bus_message **m,
const char *destination,
const char *path,
const char *interface,
const char *destination,
const char *path,
const char *interface,
- const char *member,
- sd_bus_message **m) {
+ const char *member) {
sd_bus_message *t;
int r;
sd_bus_message *t;
int r;
@@
-617,7
+617,7
@@
static int message_new_reply(
t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
t->reply_cookie = BUS_MESSAGE_COOKIE(call);
t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
t->reply_cookie = BUS_MESSAGE_COOKIE(call);
- r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_cookie);
+ r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL,
(uint32_t)
t->reply_cookie);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
@@
-647,8
+647,8
@@
_public_ int sd_bus_message_new_method_return(
_public_ int sd_bus_message_new_method_error(
sd_bus_message *call,
_public_ int sd_bus_message_new_method_error(
sd_bus_message *call,
-
const sd_bus_error *e
,
-
sd_bus_message **m
) {
+
sd_bus_message **m
,
+
const sd_bus_error *e
) {
sd_bus_message *t;
int r;
sd_bus_message *t;
int r;
@@
-697,23
+697,23
@@
_public_ int sd_bus_message_new_method_errorf(
bus_error_setfv(&error, name, format, ap);
va_end(ap);
bus_error_setfv(&error, name, format, ap);
va_end(ap);
- return sd_bus_message_new_method_error(call,
&error, m
);
+ return sd_bus_message_new_method_error(call,
m, &error
);
}
_public_ int sd_bus_message_new_method_errno(
sd_bus_message *call,
}
_public_ int sd_bus_message_new_method_errno(
sd_bus_message *call,
+ sd_bus_message **m,
int error,
int error,
- const sd_bus_error *p,
- sd_bus_message **m) {
+ const sd_bus_error *p) {
_cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
if (sd_bus_error_is_set(p))
_cleanup_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
if (sd_bus_error_is_set(p))
- return sd_bus_message_new_method_error(call,
p, m
);
+ return sd_bus_message_new_method_error(call,
m, p
);
sd_bus_error_set_errno(&berror, error);
sd_bus_error_set_errno(&berror, error);
- return sd_bus_message_new_method_error(call,
&berror, m
);
+ return sd_bus_message_new_method_error(call,
m, &berror
);
}
_public_ int sd_bus_message_new_method_errnof(
}
_public_ int sd_bus_message_new_method_errnof(
@@
-730,7
+730,7
@@
_public_ int sd_bus_message_new_method_errnof(
bus_error_set_errnofv(&berror, error, format, ap);
va_end(ap);
bus_error_set_errnofv(&berror, error, format, ap);
va_end(ap);
- return sd_bus_message_new_method_error(call,
&berror, m
);
+ return sd_bus_message_new_method_error(call,
m, &berror
);
}
int bus_message_new_synthetic_error(
}
int bus_message_new_synthetic_error(
@@
-752,7
+752,7
@@
int bus_message_new_synthetic_error(
t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
t->reply_cookie = cookie;
t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
t->reply_cookie = cookie;
- r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_cookie);
+ r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL,
(uint32_t)
t->reply_cookie);
if (r < 0)
goto fail;
if (r < 0)
goto fail;
@@
-1228,7
+1228,7
@@
static void *message_extend_body(sd_bus_message *m, size_t align, size_t sz, boo
return NULL;
if (padding > 0) {
return NULL;
if (padding > 0) {
- mem
set(p, 0
, padding);
+ mem
zero(p
, padding);
p = (uint8_t*) p + padding;
}
p = (uint8_t*) p + padding;
}
@@
-1863,7
+1863,7
@@
_public_ int sd_bus_message_open_container(
struct bus_container *c, *w;
uint32_t *array_size = NULL;
char *signature;
struct bus_container *c, *w;
uint32_t *array_size = NULL;
char *signature;
- size_t before, begin;
+ size_t before, begin
= 0
;
bool need_offsets = false;
int r;
bool need_offsets = false;
int r;
@@
-2514,7
+2514,7
@@
_public_ int sd_bus_message_append_array_iovec(
if (iov[i].iov_base)
memcpy(p, iov[i].iov_base, iov[i].iov_len);
else
if (iov[i].iov_base)
memcpy(p, iov[i].iov_base, iov[i].iov_len);
else
- mem
set(p, 0
, iov[i].iov_len);
+ mem
zero(p
, iov[i].iov_len);
p = (uint8_t*) p + iov[i].iov_len;
}
p = (uint8_t*) p + iov[i].iov_len;
}
@@
-2779,7
+2779,7
@@
int bus_message_seal(sd_bus_message *m, uint64_t cookie, usec_t timeout) {
l = BUS_MESSAGE_FIELDS_SIZE(m);
a = ALIGN8(l) - l;
if (a > 0)
l = BUS_MESSAGE_FIELDS_SIZE(m);
a = ALIGN8(l) - l;
if (a > 0)
- mem
set((uint8_t*) BUS_MESSAGE_FIELDS(m) + l, 0
, a);
+ mem
zero((uint8_t*) BUS_MESSAGE_FIELDS(m) + l
, a);
/* If this is something we can send as memfd, then let's seal
the memfd now. Note that we can send memfds as payload only
/* If this is something we can send as memfd, then let's seal
the memfd now. Note that we can send memfds as payload only
@@
-4885,6
+4885,7
@@
int bus_message_parse_fields(sd_bus_message *m) {
size_t ri;
int r;
uint32_t unix_fds = 0;
size_t ri;
int r;
uint32_t unix_fds = 0;
+ bool unix_fds_set = false;
void *offsets = NULL;
unsigned n_offsets = 0;
size_t sz = 0;
void *offsets = NULL;
unsigned n_offsets = 0;
size_t sz = 0;
@@
-5075,24
+5076,29
@@
int bus_message_parse_fields(sd_bus_message *m) {
break;
}
break;
}
- case BUS_MESSAGE_HEADER_REPLY_SERIAL:
+ case BUS_MESSAGE_HEADER_REPLY_SERIAL: {
+ uint32_t serial;
+
if (m->reply_cookie != 0)
return -EBADMSG;
if (!streq(signature, "u"))
return -EBADMSG;
if (m->reply_cookie != 0)
return -EBADMSG;
if (!streq(signature, "u"))
return -EBADMSG;
- r = message_peek_field_uint32(m, &ri, item_size, &
m->reply_cookie
);
+ r = message_peek_field_uint32(m, &ri, item_size, &
serial
);
if (r < 0)
return r;
if (r < 0)
return r;
+ m->reply_cookie = serial;
+
if (m->reply_cookie == 0)
return -EBADMSG;
break;
if (m->reply_cookie == 0)
return -EBADMSG;
break;
+ }
case BUS_MESSAGE_HEADER_UNIX_FDS:
case BUS_MESSAGE_HEADER_UNIX_FDS:
- if (unix_fds
!= 0
)
+ if (unix_fds
_set
)
return -EBADMSG;
if (!streq(signature, "u"))
return -EBADMSG;
if (!streq(signature, "u"))
@@
-5102,9
+5108,7
@@
int bus_message_parse_fields(sd_bus_message *m) {
if (r < 0)
return -EBADMSG;
if (r < 0)
return -EBADMSG;
- if (unix_fds == 0)
- return -EBADMSG;
-
+ unix_fds_set = true;
break;
default:
break;
default:
@@
-5468,14
+5472,14
@@
int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
switch ((*m)->header->type) {
case SD_BUS_MESSAGE_SIGNAL:
switch ((*m)->header->type) {
case SD_BUS_MESSAGE_SIGNAL:
- r = sd_bus_message_new_signal(bus,
(*m)->path, (*m)->interface, (*m)->member, &n
);
+ r = sd_bus_message_new_signal(bus,
&n, (*m)->path, (*m)->interface, (*m)->member
);
if (r < 0)
return r;
break;
case SD_BUS_MESSAGE_METHOD_CALL:
if (r < 0)
return r;
break;
case SD_BUS_MESSAGE_METHOD_CALL:
- r = sd_bus_message_new_method_call(bus,
(*m)->destination, (*m)->path, (*m)->interface, (*m)->member, &n
);
+ r = sd_bus_message_new_method_call(bus,
&n, (*m)->destination, (*m)->path, (*m)->interface, (*m)->member
);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-5489,7
+5493,7
@@
int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
return -ENOMEM;
n->reply_cookie = (*m)->reply_cookie;
return -ENOMEM;
n->reply_cookie = (*m)->reply_cookie;
- r = message_append_field_uint32(n, BUS_MESSAGE_HEADER_REPLY_SERIAL, n->reply_cookie);
+ r = message_append_field_uint32(n, BUS_MESSAGE_HEADER_REPLY_SERIAL,
(uint32_t)
n->reply_cookie);
if (r < 0)
return r;
if (r < 0)
return r;