[systemd-commits] 4 commits - Makefile.am src/libsystemd-bus src/libsystemd-dhcp src/shared

Zbigniew Jędrzejewski-Szmek zbyszek at kemper.freedesktop.org
Tue Dec 31 10:01:20 PST 2013


 Makefile.am                            |   13 ++++++-----
 src/libsystemd-bus/test-bus-marshal.c  |    4 +--
 src/libsystemd-dhcp/dhcp-client.c      |    5 ++--
 src/libsystemd-dhcp/test-dhcp-client.c |    1 
 src/shared/sleep-config.c              |   38 +++++++++++++++++----------------
 5 files changed, 34 insertions(+), 27 deletions(-)

New commits:
commit 9b55cd5665d94e2245a4ca90d2548bbcfe8c34fb
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Dec 31 12:51:46 2013 -0500

    build-sys: make test output a bit nicer

diff --git a/Makefile.am b/Makefile.am
index 19d987d..5f31daa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4900,8 +4900,9 @@ install-tree: all
 # exclude the one perl script we have in there
 valgrind-tests: $(TESTS)
 	$(AM_V_GEN)for f in $(filter-out %.pl, $^); do \
-		echo "Running $$f"; \
+		echo -e "$${x}Running $$f"; \
 	        libtool --mode=execute valgrind -q --leak-check=full --max-stackframe=4194400 --error-exitcode=55 $(builddir)/$$f ; \
+		x="\n\n"; \
 	done
 
 exported-%: %
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 069b084..317e3a7 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -262,8 +262,8 @@ int main(int argc, char *argv[]) {
         fflush(ms);
         assert_se(!ferror(ms));
 
-        printf("<%.*s>", (int) first_size, first);
-        printf("<%.*s>", (int) third_size, third);
+        printf("<%.*s>\n", (int) first_size, first);
+        printf("<%.*s>\n", (int) third_size, third);
 
         assert_se(first_size == third_size);
         assert_se(memcmp(first, third, third_size) == 0);

commit 7a7c74cae4db0c35cbe54d9bad8418a605cb870f
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Dec 31 11:57:38 2013 -0500

    dhcp: fix creation of req_opts array
    
    GREEDY_REALLOC needs to have two size variables: one for the
    allocated size, and a second one for the used size. Using
    the allocated size only lead to leaving some elements unitialized
    and assigning some more than once.

diff --git a/src/libsystemd-dhcp/dhcp-client.c b/src/libsystemd-dhcp/dhcp-client.c
index 9f7a826..b9492a5 100644
--- a/src/libsystemd-dhcp/dhcp-client.c
+++ b/src/libsystemd-dhcp/dhcp-client.c
@@ -54,6 +54,7 @@ struct sd_dhcp_client {
         union sockaddr_union link;
         sd_event_source *receive_message;
         uint8_t *req_opts;
+        size_t req_opts_allocated;
         size_t req_opts_size;
         be32_t last_addr;
         struct ether_addr mac_addr;
@@ -115,11 +116,11 @@ int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
                 if (client->req_opts[i] == option)
                         return -EEXIST;
 
-        if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size,
+        if (!GREEDY_REALLOC(client->req_opts, client->req_opts_allocated,
                             client->req_opts_size + 1))
                 return -ENOMEM;
 
-        client->req_opts[client->req_opts_size - 1] = option;
+        client->req_opts[client->req_opts_size++] = option;
 
         return 0;
 }
diff --git a/src/libsystemd-dhcp/test-dhcp-client.c b/src/libsystemd-dhcp/test-dhcp-client.c
index 617236b..929b869 100644
--- a/src/libsystemd-dhcp/test-dhcp-client.c
+++ b/src/libsystemd-dhcp/test-dhcp-client.c
@@ -85,6 +85,7 @@ static void test_request_basic(sd_event *e)
         assert(sd_dhcp_client_set_request_option(client, 33) == 0);
         assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
         assert(sd_dhcp_client_set_request_option(client, 44) == 0);
+        assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
 }
 
 static uint16_t client_checksum(void *buf, int len)

commit aa9ed6538985d667aa6a0264c59622a51384ccd6
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Dec 31 11:48:04 2013 -0500

    build-sys: make test-dhcp-* statically linked
    
    This makes them behave like everything else following
    48d7417d3 'build-sys: link most internal libraries statically'.

diff --git a/Makefile.am b/Makefile.am
index 8e5f511..19d987d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3926,8 +3926,8 @@ noinst_LTLIBRARIES += \
 	libsystemd-dhcp.la
 
 libsystemd_dhcp_la_LIBADD = \
-	libsystemd-shared.la \
-	libsystemd-bus.la
+	libsystemd-bus-internal.la \
+	libsystemd-shared.la
 
 test_dhcp_option_SOURCES = \
 	src/libsystemd-dhcp/dhcp-protocol.h \
@@ -3945,9 +3945,11 @@ test_dhcp_client_SOURCES = \
 	src/libsystemd-dhcp/test-dhcp-client.c
 
 test_dhcp_client_LDADD = \
+	libsystemd-bus-internal.la \
+	libsystemd-daemon-internal.la \
+	libsystemd-id128-internal.la \
 	libsystemd-dhcp.la \
-	libsystemd-shared.la \
-	libsystemd-bus.la
+	libsystemd-shared.la
 
 tests += \
 	test-dhcp-option \

commit dabeaa460d9fa01db645116775f53e3071977503
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date:   Tue Dec 31 11:23:58 2013 -0500

    sleep-config: fix double free
    
    Before 34a3baa4d 'sleep-config: Dereference pointer before check for NULL'
    oom conditions would not be detected properly. After that commit, a double
    free was performed.
    
    Rework the whole function to be easier to understand, and also replace
    strv_split_nulstr with strv_new, since we know the strings anyway.

diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c
index b2a0787..70a0896 100644
--- a/src/shared/sleep-config.c
+++ b/src/shared/sleep-config.c
@@ -28,11 +28,14 @@
 #include "strv.h"
 #include "util.h"
 
-int parse_sleep_config(const char *verb, char ***modes, char ***states) {
+#define USE(x, y) do{ (x) = (y); (y) = NULL; } while(0)
+
+int parse_sleep_config(const char *verb, char ***_modes, char ***_states) {
         _cleanup_strv_free_ char
                 **suspend_mode = NULL, **suspend_state = NULL,
                 **hibernate_mode = NULL, **hibernate_state = NULL,
                 **hybrid_mode = NULL, **hybrid_state = NULL;
+        char **modes, **states;
 
         const ConfigTableItem items[] = {
                 { "Sleep",   "SuspendMode",      config_parse_strv,  0, &suspend_mode  },
@@ -59,47 +62,46 @@ int parse_sleep_config(const char *verb, char ***modes, char ***states) {
 
         if (streq(verb, "suspend")) {
                 /* empty by default */
-                *modes = suspend_mode;
+                USE(modes, suspend_mode);
 
                 if (suspend_state)
-                        *states = suspend_state;
+                        USE(states, suspend_state);
                 else
-                        *states = strv_split_nulstr("mem\0standby\0freeze\0");
+                        states = strv_new("mem", "standby", "freeze", NULL);
 
-                suspend_mode = suspend_state = NULL;
         } else if (streq(verb, "hibernate")) {
                 if (hibernate_mode)
-                        *modes = hibernate_mode;
+                        USE(modes, hibernate_mode);
                 else
-                        *modes = strv_split_nulstr("platform\0shutdown\0");
+                        modes = strv_new("platform", "shutdown", NULL);
 
                 if (hibernate_state)
-                        *states = hibernate_state;
+                        USE(states, hibernate_state);
                 else
-                        *states = strv_split_nulstr("disk\0");
+                        states = strv_new("disk", NULL);
 
-                hibernate_mode = hibernate_state = NULL;
         } else if (streq(verb, "hybrid-sleep")) {
                 if (hybrid_mode)
-                        *modes = hybrid_mode;
+                        USE(modes, hybrid_mode);
                 else
-                        *modes = strv_split_nulstr("suspend\0platform\0shutdown\0");
+                        modes = strv_new("suspend", "platform", "shutdown", NULL);
 
                 if (hybrid_state)
-                        *states = hybrid_state;
+                        USE(states, hybrid_state);
                 else
-                        *states = strv_split_nulstr("disk\0");
+                        states = strv_new("disk", NULL);
 
-                hybrid_mode = hybrid_state = NULL;
         } else
                 assert_not_reached("what verb");
 
-        if (!*modes || !*states) {
-                strv_free(*modes);
-                strv_free(*states);
+        if ((!modes && !streq(verb, "suspend")) || !states) {
+                strv_free(modes);
+                strv_free(states);
                 return log_oom();
         }
 
+        *_modes = modes;
+        *_states = states;
         return 0;
 }
 



More information about the systemd-commits mailing list