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

Tom Gundersen tomegun at kemper.freedesktop.org
Wed Sep 17 10:13:49 PDT 2014


 src/libsystemd-network/test-dhcp-option.c |    1 +
 src/network/networkd-dhcp4.c              |   19 +++++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

New commits:
commit 6f42877282a7237f3aa840403047b7cc18d7faa6
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Sep 17 19:07:56 2014 +0200

    libsystemd-network: dhcp-test - assert that malloc0 succeeds
    
    Otherwise we would get a nullptr dereference later on.
    
    Found by coverity. Fixes CID #1237655.

diff --git a/src/libsystemd-network/test-dhcp-option.c b/src/libsystemd-network/test-dhcp-option.c
index 7a0fac8..63cdc7a 100644
--- a/src/libsystemd-network/test-dhcp-option.c
+++ b/src/libsystemd-network/test-dhcp-option.c
@@ -115,6 +115,7 @@ static DHCPMessage *create_message(uint8_t *options, uint16_t optlen,
         size_t len = sizeof(DHCPMessage) + optlen;
 
         message = malloc0(len);
+        assert_se(message);
 
         if (options && optlen)
                 memcpy(&message->options, options, optlen);

commit f414a269b378d526b8b26c5b52743360b43965ce
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Sep 17 19:00:55 2014 +0200

    networkd: dhcp4 - fix unchecked return value
    
    Found by coverity. CID #1237529 and #1237528.

diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index e0b3aca..e451af8 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -178,7 +178,7 @@ static int dhcp_lease_lost(Link *link) {
         struct in_addr addr;
         struct in_addr netmask;
         struct in_addr gateway;
-        unsigned prefixlen;
+        unsigned prefixlen = 0;
         int r;
 
         assert(link);
@@ -237,15 +237,18 @@ static int dhcp_lease_lost(Link *link) {
                         }
                 }
 
-                sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
-                sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
-                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
+                r = sd_dhcp_lease_get_address(link->dhcp_lease, &addr);
+                if (r >= 0) {
+                        r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask);
+                        if (r >= 0)
+                                prefixlen = in_addr_netmask_to_prefixlen(&netmask);
 
-                address->family = AF_INET;
-                address->in_addr.in = addr;
-                address->prefixlen = prefixlen;
+                        address->family = AF_INET;
+                        address->in_addr.in = addr;
+                        address->prefixlen = prefixlen;
 
-                address_drop(address, link, &link_address_drop_handler);
+                       address_drop(address, link, &link_address_drop_handler);
+                }
         }
 
         if (link->network->dhcp_mtu) {



More information about the systemd-commits mailing list