From 04a3af3c6d434bcde7118440f13d55c910eb9ba0 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 21 Feb 2024 11:03:35 +0100 Subject: [PATCH] tree-wide: be more careful when passing literal integers to "t" bus message fields Since we use varargs for sd_message_append() we need to make sure the parameters we pass are actually 64bit wide, if "t" is used. Hence cast appropriately if necessary. I went through the whole tree, and in most cases we got it right, but there are some cases we missed so far. Inspired by: #31420 --- src/core/dbus-execute.c | 4 ++-- src/core/dbus-service.c | 2 +- src/core/dbus-unit.c | 2 +- src/machine/machinectl.c | 2 +- src/portable/portablectl.c | 2 +- src/shared/bus-unit-util.c | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c index b2e5ae4f85f..6d2247a8401 100644 --- a/src/core/dbus-execute.c +++ b/src/core/dbus-execute.c @@ -492,7 +492,7 @@ static int property_get_bind_paths( c->bind_mounts[i].source, c->bind_mounts[i].destination, c->bind_mounts[i].ignore_enoent, - c->bind_mounts[i].recursive ? (uint64_t) MS_REC : (uint64_t) 0); + c->bind_mounts[i].recursive ? (uint64_t) MS_REC : UINT64_C(0)); if (r < 0) return r; } @@ -911,7 +911,7 @@ static int bus_property_get_exec_dir_symlink( for (size_t i = 0; i < d->n_items; i++) STRV_FOREACH(dst, d->items[i].symlinks) { - r = sd_bus_message_append(reply, "(sst)", d->items[i].path, *dst, 0 /* flags, unused for now */); + r = sd_bus_message_append(reply, "(sst)", d->items[i].path, *dst, UINT64_C(0) /* flags, unused for now */); if (r < 0) return r; } diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 77cf6f003d7..ff970df9574 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -61,7 +61,7 @@ static int property_get_open_files( return r; LIST_FOREACH(open_files, of, *open_files) { - r = sd_bus_message_append(reply, "(sst)", of->path, of->fdname, of->flags); + r = sd_bus_message_append(reply, "(sst)", of->path, of->fdname, (uint64_t) of->flags); if (r < 0) return r; } diff --git a/src/core/dbus-unit.c b/src/core/dbus-unit.c index eda9f6c74e1..9e8ff2cc130 100644 --- a/src/core/dbus-unit.c +++ b/src/core/dbus-unit.c @@ -1239,7 +1239,7 @@ static int property_get_cgroup_id( assert(reply); CGroupRuntime *crt = unit_get_cgroup_runtime(u); - return sd_bus_message_append(reply, "t", crt ? crt->cgroup_id : 0); + return sd_bus_message_append(reply, "t", crt ? crt->cgroup_id : UINT64_C(0)); } static int append_process(sd_bus_message *reply, const char *p, PidRef *pid, Set *pids) { diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index e1bc9324439..9c0aa035e5b 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -1130,7 +1130,7 @@ static int copy_files(int argc, char *argv[], void *userdata) { return bus_log_create_error(r); if (arg_force) { - r = sd_bus_message_append(m, "t", MACHINE_COPY_REPLACE); + r = sd_bus_message_append(m, "t", (uint64_t) MACHINE_COPY_REPLACE); if (r < 0) return bus_log_create_error(r); } diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index 1867fc8a1d0..db5e4febe0a 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -1171,7 +1171,7 @@ static int is_image_attached(int argc, char *argv[], void *userdata) { return r; if (!strv_isempty(arg_extension_images)) { - r = sd_bus_message_append(m, "t", 0); + r = sd_bus_message_append(m, "t", UINT64_C(0)); if (r < 0) return bus_log_create_error(r); } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index dae7dd5e36f..53da9bc3c24 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1419,12 +1419,12 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con if (r < 0) return log_error_errno(r, "Failed to parse resource limit: %s", eq); - r = sd_bus_message_append(m, "(sv)", field, "t", l.rlim_max); + r = sd_bus_message_append(m, "(sv)", field, "t", (uint64_t) l.rlim_max); if (r < 0) return bus_log_create_error(r); sn = strjoina(field, "Soft"); - r = sd_bus_message_append(m, "(sv)", sn, "t", l.rlim_cur); + r = sd_bus_message_append(m, "(sv)", sn, "t", (uint64_t) l.rlim_cur); if (r < 0) return bus_log_create_error(r); @@ -2167,7 +2167,7 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con return bus_log_create_error(r); STRV_FOREACH_PAIR(source, destination, symlinks) { - r = sd_bus_message_append(m, "(sst)", *source, *destination, 0); + r = sd_bus_message_append(m, "(sst)", *source, *destination, UINT64_C(0)); if (r < 0) return bus_log_create_error(r); } -- 2.47.3