From: Samuel Ortiz Date: Thu, 14 Oct 2010 13:43:58 +0000 (+0200) Subject: ipconfig: Do not call inet_network() with a NULL pointer X-Git-Tag: 0.63~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2766eed8b364475972cb0f2e306b6c3188877e1e;p=platform%2Fupstream%2Fconnman.git ipconfig: Do not call inet_network() with a NULL pointer inet_network() segfaults when given a NULL pointer as an argument. --- diff --git a/src/ipconfig.c b/src/ipconfig.c index 1ce07e5..a872dff 100644 --- a/src/ipconfig.c +++ b/src/ipconfig.c @@ -117,14 +117,21 @@ void connman_ipaddress_free(struct connman_ipaddress *ipaddress) unsigned char __connman_ipconfig_netmask_prefix_len(const char *netmask) { - unsigned char bits = 0; - in_addr_t mask = inet_network(netmask); - in_addr_t host = ~mask; + unsigned char bits; + in_addr_t mask; + in_addr_t host; + + if (netmask == NULL) + return 32; + + mask = inet_network(netmask); + host = ~mask; /* a valid netmask must be 2^n - 1 */ if ((host & (host + 1)) != 0) return -1; + bits = 0; for (; mask; mask <<= 1) ++bits; @@ -176,11 +183,7 @@ void connman_ipaddress_set_ipv4(struct connman_ipaddress *ipaddress, if (ipaddress == NULL) return; - if (netmask != NULL) - ipaddress->prefixlen = - __connman_ipconfig_netmask_prefix_len(netmask); - else - ipaddress->prefixlen = 32; + ipaddress->prefixlen = __connman_ipconfig_netmask_prefix_len(netmask); g_free(ipaddress->local); ipaddress->local = g_strdup(address);