diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-28 11:55:49 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-07-29 15:54:53 +0200 |
commit | 62b21e2e89b68f0a1fb209e6677c61fdb4c32b34 (patch) | |
tree | 935b513d366d3f000e082e021fda87a93411de53 | |
parent | bus-util: convert bus_log_{parse,create}_error into defines (diff) | |
download | systemd-62b21e2e89b68f0a1fb209e6677c61fdb4c32b34.tar.xz systemd-62b21e2e89b68f0a1fb209e6677c61fdb4c32b34.zip |
shared/bus-util: fix dbus serialization of {RestartPrevent,RestartForce,Success}ExitStatus
We were passing 1/4th of the size in bytes as argument. So depending
on the size of the array, either we'd only transfer a subset of values,
or we'd get an alignment error.
-rw-r--r-- | src/core/dbus-service.c | 16 | ||||
-rw-r--r-- | src/shared/bus-unit-util.c | 14 | ||||
-rw-r--r-- | src/systemctl/systemctl.c | 16 |
3 files changed, 23 insertions, 23 deletions
diff --git a/src/core/dbus-service.c b/src/core/dbus-service.c index 0b873fb486..fbda8d8a4c 100644 --- a/src/core/dbus-service.c +++ b/src/core/dbus-service.c @@ -159,18 +159,18 @@ static int bus_set_transient_exit_status( sd_bus_error *error) { const int32_t *status, *signal; - size_t sz_status, sz_signal, i; + size_t n_status, n_signal, i; int r; r = sd_bus_message_enter_container(message, 'r', "aiai"); if (r < 0) return r; - r = sd_bus_message_read_array(message, 'i', (const void **) &status, &sz_status); + r = sd_bus_message_read_array(message, 'i', (const void **) &status, &n_status); if (r < 0) return r; - r = sd_bus_message_read_array(message, 'i', (const void **) &signal, &sz_signal); + r = sd_bus_message_read_array(message, 'i', (const void **) &signal, &n_signal); if (r < 0) return r; @@ -178,16 +178,16 @@ static int bus_set_transient_exit_status( if (r < 0) return r; - sz_status /= sizeof(int32_t); - sz_signal /= sizeof(int32_t); + n_status /= sizeof(int32_t); + n_signal /= sizeof(int32_t); - if (sz_status == 0 && sz_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) { + if (n_status == 0 && n_signal == 0 && !UNIT_WRITE_FLAGS_NOOP(flags)) { exit_status_set_free(status_set); unit_write_settingf(u, flags, name, "%s=", name); return 1; } - for (i = 0; i < sz_status; i++) { + for (i = 0; i < n_status; i++) { if (status[i] < 0 || status[i] > 255) return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid status code in %s: %"PRIi32, name, status[i]); @@ -200,7 +200,7 @@ static int bus_set_transient_exit_status( } } - for (i = 0; i < sz_signal; i++) { + for (i = 0; i < n_signal; i++) { const char *str; str = signal_to_string((int) signal[i]); diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 322204dd22..99511d338a 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1439,7 +1439,7 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con if (STR_IN_SET(field, "RestartPreventExitStatus", "RestartForceExitStatus", "SuccessExitStatus")) { _cleanup_free_ int *status = NULL, *signal = NULL; - size_t sz_status = 0, sz_signal = 0; + size_t n_status = 0, n_signal = 0; const char *p; for (p = eq;;) { @@ -1460,17 +1460,17 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con if (val < 0) return log_error_errno(r, "Invalid status or signal %s in %s: %m", word, field); - signal = reallocarray(signal, sz_signal + 1, sizeof(int)); + signal = reallocarray(signal, n_signal + 1, sizeof(int)); if (!signal) return log_oom(); - signal[sz_signal++] = val; + signal[n_signal++] = val; } else { - status = reallocarray(status, sz_status + 1, sizeof(int)); + status = reallocarray(status, n_status + 1, sizeof(int)); if (!status) return log_oom(); - status[sz_status++] = val; + status[n_status++] = val; } } @@ -1490,11 +1490,11 @@ static int bus_append_service_property(sd_bus_message *m, const char *field, con if (r < 0) return bus_log_create_error(r); - r = sd_bus_message_append_array(m, 'i', status, sz_status); + r = sd_bus_message_append_array(m, 'i', status, n_status * sizeof(int)); if (r < 0) return bus_log_create_error(r); - r = sd_bus_message_append_array(m, 'i', signal, sz_signal); + r = sd_bus_message_append_array(m, 'i', signal, n_signal * sizeof(int)); if (r < 0) return bus_log_create_error(r); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index b9a7d488bd..9e8095c8b7 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -4911,17 +4911,17 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m } else if (endswith(name, "ExitStatus") && streq(contents, "aiai")) { const int32_t *status, *signal; - size_t sz_status, sz_signal, i; + size_t n_status, n_signal, i; r = sd_bus_message_enter_container(m, 'r', "aiai"); if (r < 0) return bus_log_parse_error(r); - r = sd_bus_message_read_array(m, 'i', (const void **) &status, &sz_status); + r = sd_bus_message_read_array(m, 'i', (const void **) &status, &n_status); if (r < 0) return bus_log_parse_error(r); - r = sd_bus_message_read_array(m, 'i', (const void **) &signal, &sz_signal); + r = sd_bus_message_read_array(m, 'i', (const void **) &signal, &n_signal); if (r < 0) return bus_log_parse_error(r); @@ -4929,10 +4929,10 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m if (r < 0) return bus_log_parse_error(r); - sz_status /= sizeof(int32_t); - sz_signal /= sizeof(int32_t); + n_status /= sizeof(int32_t); + n_signal /= sizeof(int32_t); - if (all || sz_status > 0 || sz_signal > 0) { + if (all || n_status > 0 || n_signal > 0) { bool first = true; if (!value) { @@ -4940,7 +4940,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m fputc('=', stdout); } - for (i = 0; i < sz_status; i++) { + for (i = 0; i < n_status; i++) { if (status[i] < 0 || status[i] > 255) continue; @@ -4952,7 +4952,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m printf("%"PRIi32, status[i]); } - for (i = 0; i < sz_signal; i++) { + for (i = 0; i < n_signal; i++) { const char *str; str = signal_to_string((int) signal[i]); |