From 15e1145ab26974f2d781b21827103d3525d3f64d Mon Sep 17 00:00:00 2001 From: Ismo Puustinen Date: Wed, 13 Sep 2017 14:02:28 +0300 Subject: [PATCH 1/2] Initialize boolean value to false. This means that the value is really false if the D-Bus value assigned to it is false. Otherwise the boolean value might contain uninitialized bits, rendering the value true. Signed-off-by: Ismo Puustinen --- test_bus.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test_bus.c b/test_bus.c index 006c373..403d0bb 100644 --- a/test_bus.c +++ b/test_bus.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) int r = -1, i; const char *action_id; const char *name = NULL; - bool *allowed; + bool *allowed = false; gid_t supplementary_groups[argc]; if (argc < 2) { @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) r = sd_bus_message_open_container(msg, SD_BUS_TYPE_ARRAY, "{sv}"); if (r < 0) goto end; - + r = sd_bus_message_open_container(msg, SD_BUS_TYPE_DICT_ENTRY, "sv"); if (r < 0) goto end; @@ -100,16 +100,16 @@ int main(int argc, char *argv[]) r = sd_bus_message_append(msg, "s", "name"); if (r < 0) goto end; - + r = sd_bus_message_append(msg, "v", "s", name); if (r < 0) goto end; - + /* dict entry */ r = sd_bus_message_close_container(msg); if (r < 0) goto end; - + /* array */ r = sd_bus_message_close_container(msg); if (r < 0) @@ -135,7 +135,7 @@ int main(int argc, char *argv[]) r = sd_bus_message_append(msg, "s", ""); if (r < 0) goto end; - + r = sd_bus_call(bus, msg, 0, NULL, &reply); if (r < 0) { fprintf(stderr, "D-Bus method call failed: %s\n", strerror(-r)); From f18f11eb93b007786cd825646e0547e2b8ee8472 Mon Sep 17 00:00:00 2001 From: Ismo Puustinen Date: Fri, 6 Oct 2017 15:03:25 +0300 Subject: [PATCH 2/2] Fix problems found by static analysis. --- groupcheck.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/groupcheck.c b/groupcheck.c index 4d2d989..7a75935 100644 --- a/groupcheck.c +++ b/groupcheck.c @@ -350,9 +350,10 @@ static int parse_subject(sd_bus_message *m, struct subject *subject) return r; if (strlen(value) >= MAX_NAME_SIZE) - return r; + return -EINVAL; strncpy(subject->data.s.session_id, value, MAX_NAME_SIZE); + subject->data.s.session_id[MAX_NAME_SIZE-1] = '\0'; r = sd_bus_message_exit_container(m); if (r < 0) @@ -375,6 +376,7 @@ static int parse_subject(sd_bus_message *m, struct subject *subject) return -EINVAL; strncpy(subject->data.s.session_id, value, MAX_NAME_SIZE); + subject->data.s.session_id[MAX_NAME_SIZE-1] = '\0'; r = sd_bus_message_exit_container(m); if (r < 0)