summaryrefslogtreecommitdiffstats
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-09-06 22:03:01 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-09-07 00:34:43 +0200
commit925095a6db6793d05622ed666cdc8af7d80b7ce6 (patch)
tree2c1859f9386bb1bd1e9f80458ba15c507bcd8b66 /src/shared
parentman: CAP_SYS_ADMIN does NOT grant any permission for dbus API (diff)
downloadsystemd-925095a6db6793d05622ed666cdc8af7d80b7ce6.tar.xz
systemd-925095a6db6793d05622ed666cdc8af7d80b7ce6.zip
dm-util: get rid of flex array in middle of structure
Fixes: #33936
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dm-util.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/shared/dm-util.c b/src/shared/dm-util.c
index 66c1e13439..498df418de 100644
--- a/src/shared/dm-util.c
+++ b/src/shared/dm-util.c
@@ -10,29 +10,37 @@
int dm_deferred_remove_cancel(const char *name) {
_cleanup_close_ int fd = -EBADF;
- struct message {
+
+ struct combined {
struct dm_ioctl dm_ioctl;
struct dm_target_msg dm_target_msg;
- char msg_text[STRLEN("@cancel_deferred_remove") + 1];
- } _packed_ message = {
- .dm_ioctl = {
+ } _packed_;
+
+ union message {
+ struct combined combined;
+ struct {
+ uint8_t space[offsetof(struct combined, dm_target_msg.message)];
+ char text[STRLEN("@cancel_deferred_remove") + 1];
+ } _packed_;
+ } message = {
+ .combined.dm_ioctl = {
.version = {
DM_VERSION_MAJOR,
DM_VERSION_MINOR,
DM_VERSION_PATCHLEVEL
},
- .data_size = sizeof(struct message),
- .data_start = sizeof(struct dm_ioctl),
+ .data_size = sizeof(union message),
+ .data_start = offsetof(union message, combined.dm_target_msg),
},
- .msg_text = "@cancel_deferred_remove",
};
assert(name);
- if (strlen(name) >= sizeof(message.dm_ioctl.name))
+ if (strlen(name) >= sizeof(message.combined.dm_ioctl.name))
return -ENODEV; /* A device with a name longer than this cannot possibly exist */
- strncpy_exact(message.dm_ioctl.name, name, sizeof(message.dm_ioctl.name));
+ strncpy_exact(message.combined.dm_ioctl.name, name, sizeof(message.combined.dm_ioctl.name));
+ strncpy_exact(message.text, "@cancel_deferred_remove", sizeof(message.text));
fd = open("/dev/mapper/control", O_RDWR|O_CLOEXEC);
if (fd < 0)