summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-22 19:32:09 +0200
committerLennart Poettering <lennart@poettering.net>2020-04-23 08:54:30 +0200
commit0cd41757d061c4b0a85532499f29f23651279234 (patch)
treef503f17a29c1e57ec82d07257c0318f80dd4e90e /src
parentsd-bus: Add sd_bus_get/set_allow_interactive_authorization docs (diff)
downloadsystemd-0cd41757d061c4b0a85532499f29f23651279234.tar.xz
systemd-0cd41757d061c4b0a85532499f29f23651279234.zip
sd-bus: work around ubsan warning
ubsan complains that we add an offset to a NULL ptr here in some cases. Which isn't really a bug though, since we only use it as the end condition for a for loop, but we can still fix it... Fixes: #15522
Diffstat (limited to 'src')
-rw-r--r--src/basic/strv.h2
-rw-r--r--src/core/namespace.c5
-rw-r--r--src/libsystemd/sd-bus/bus-message.c15
-rw-r--r--src/libsystemd/sd-bus/bus-objects.c6
-rw-r--r--src/systemctl/systemctl.c2
5 files changed, 18 insertions, 12 deletions
diff --git a/src/basic/strv.h b/src/basic/strv.h
index dd3323c223..d7166ce5f3 100644
--- a/src/basic/strv.h
+++ b/src/basic/strv.h
@@ -111,7 +111,7 @@ bool strv_overlap(char * const *a, char * const *b) _pure_;
(s)--)
#define STRV_FOREACH_PAIR(x, y, l) \
- for ((x) = (l), (y) = (x+1); (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
+ for ((x) = (l), (y) = (x) ? (x+1) : NULL; (x) && *(x) && *(y); (x) += 2, (y) = (x + 1))
char **strv_sort(char **l);
void strv_print(char * const *l);
diff --git a/src/core/namespace.c b/src/core/namespace.c
index d4d6970af3..36bc95a2df 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -1624,8 +1624,9 @@ int setup_namespace(
r = 0;
finish:
- for (m = mounts; m < mounts + n_mounts; m++)
- mount_entry_done(m);
+ if (n_mounts > 0)
+ for (m = mounts; m < mounts + n_mounts; m++)
+ mount_entry_done(m);
free(mounts);
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index e18957e354..0af9cedf5a 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -1298,19 +1298,18 @@ static int message_add_offset(sd_bus_message *m, size_t offset) {
}
static void message_extend_containers(sd_bus_message *m, size_t expand) {
- struct bus_container *c;
-
assert(m);
if (expand <= 0)
return;
- /* Update counters */
- for (c = m->containers; c < m->containers + m->n_containers; c++) {
+ if (m->n_containers <= 0)
+ return;
+ /* Update counters */
+ for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++)
if (c->array_size)
*c->array_size += expand;
- }
}
static void *message_extend_body(
@@ -1373,7 +1372,6 @@ static void *message_extend_body(
if (r < 0)
return NULL;
} else {
- struct bus_container *c;
void *op;
size_t os, start_part, end_part;
@@ -1394,8 +1392,9 @@ static void *message_extend_body(
}
/* Readjust pointers */
- for (c = m->containers; c < m->containers + m->n_containers; c++)
- c->array_size = adjust_pointer(c->array_size, op, os, part->data);
+ if (m->n_containers > 0)
+ for (struct bus_container *c = m->containers; c < m->containers + m->n_containers; c++)
+ c->array_size = adjust_pointer(c->array_size, op, os, part->data);
m->error.message = (const char*) adjust_pointer(m->error.message, op, os, part->data);
}
diff --git a/src/libsystemd/sd-bus/bus-objects.c b/src/libsystemd/sd-bus/bus-objects.c
index 12ade498a9..913d6eca8a 100644
--- a/src/libsystemd/sd-bus/bus-objects.c
+++ b/src/libsystemd/sd-bus/bus-objects.c
@@ -56,12 +56,18 @@ static int node_vtable_get_userdata(
static void *vtable_method_convert_userdata(const sd_bus_vtable *p, void *u) {
assert(p);
+ if (!u)
+ return SIZE_TO_PTR(p->x.method.offset); /* don't add offset on NULL, to make ubsan happy */
+
return (uint8_t*) u + p->x.method.offset;
}
static void *vtable_property_convert_userdata(const sd_bus_vtable *p, void *u) {
assert(p);
+ if (!u)
+ return SIZE_TO_PTR(p->x.property.offset); /* as above */
+
return (uint8_t*) u + p->x.property.offset;
}
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 64e23f0734..d319d5d375 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -410,7 +410,7 @@ static int output_units_list(const UnitInfo *unit_infos, unsigned c) {
if (arg_full)
table_set_width(table, 0);
- for (u = unit_infos; u < unit_infos + c; u++) {
+ for (u = unit_infos; unit_infos && u < unit_infos + c; u++) {
_cleanup_free_ char *j = NULL;
const char *on_underline = "", *on_loaded = "", *on_active = "";
const char *on_circle = "", *id;