[systemd-commits] 2 commits - src/libsystemd-rtnl

Tom Gundersen tomegun at kemper.freedesktop.org
Fri Nov 8 03:14:28 PST 2013


 src/libsystemd-rtnl/rtnl-message.c |   10 ++++++----
 src/libsystemd-rtnl/test-rtnl.c    |    4 ++--
 2 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit 8e337e6438e1168d9a3bf8e623a26b2211290c24
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Nov 8 12:14:28 2013 +0100

    rtnl: message - initialize all memory
    
    Including the padding, which should not really be needed, but let's keep valgrind happy.

diff --git a/src/libsystemd-rtnl/rtnl-message.c b/src/libsystemd-rtnl/rtnl-message.c
index 85cf55a..941bd96 100644
--- a/src/libsystemd-rtnl/rtnl-message.c
+++ b/src/libsystemd-rtnl/rtnl-message.c
@@ -187,6 +187,7 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
         uint32_t rta_length, message_length;
         struct nlmsghdr *new_hdr;
         struct rtattr *rta;
+        char *padding;
 
         assert_return(m, -EINVAL);
         assert_return(m->hdr, -EINVAL);
@@ -194,10 +195,9 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
         assert_return(data, -EINVAL);
         assert_return(data_length > 0, -EINVAL);
 
-        /* get the size of the new rta attribute (without padding at the end) */
+        /* get the size of the new rta attribute (with padding at the end) */
         rta_length = RTA_LENGTH(data_length);
-        /* get the new message size (with padding between the old message and the new attrib,
-         * but no padding after)
+        /* get the new message size (with padding at the end)
          */
         message_length = m->hdr->nlmsg_len + RTA_ALIGN(rta_length);
 
@@ -218,7 +218,9 @@ static int add_rtattr(sd_rtnl_message *m, unsigned short type, const void *data,
         /* we don't deal with the case where the user lies about the type and gives us
          * too little data (so don't do that)
          */
-        memcpy(RTA_DATA(rta), data, data_length);
+        padding = mempcpy(RTA_DATA(rta), data, data_length);
+        /* make sure also the padding at the end of the message is initialized */
+        memset(padding, '\0', (unsigned char *) m->hdr + m->hdr->nlmsg_len - (unsigned char *) padding);
 
         return 0;
 }

commit 8e1519bddb5eefedac2d9c4bf6f6e6b4d5e8ce81
Author: Tom Gundersen <teg at jklm.no>
Date:   Fri Nov 8 11:18:51 2013 +0100

    test-rtnl: fix typo

diff --git a/src/libsystemd-rtnl/test-rtnl.c b/src/libsystemd-rtnl/test-rtnl.c
index 39a83f3..912cc66 100644
--- a/src/libsystemd-rtnl/test-rtnl.c
+++ b/src/libsystemd-rtnl/test-rtnl.c
@@ -137,7 +137,7 @@ int main(void) {
         assert(sd_rtnl_message_get_type(r, &type) >= 0);
         assert(type == RTM_NEWLINK);
 
-        assert(sd_rtnl_message_read(m, &type, data) == 0);
+        assert(sd_rtnl_message_read(m, &type, &data) == 0);
         assert((r = sd_rtnl_message_unref(r)) == NULL);
 
         assert(sd_rtnl_send_with_reply_and_block(rtnl, m, -1, &r) == -EPERM);
@@ -153,7 +153,7 @@ int main(void) {
         assert(type == IFLA_MTU);
         assert(*mtu_reply == 0);
 
-        assert(sd_rtnl_message_read(m, &type, data) == 0);
+        assert(sd_rtnl_message_read(m, &type, &data) == 0);
 
         assert(sd_rtnl_send_with_reply_and_block(rtnl, m, -1, &r) >= 0);
         while (sd_rtnl_message_read(r, &type, &data) > 0) {



More information about the systemd-commits mailing list