summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-10-14 15:43:58 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-10-14 15:43:58 +0200
commit2766eed8b364475972cb0f2e306b6c3188877e1e (patch)
tree5731c5676bdb252317c61e998dff81fa64494eed /src
parentfe52075aa0f7e31e25138794e46640ccd49aa3de (diff)
downloadconnman-2766eed8b364475972cb0f2e306b6c3188877e1e.tar.gz
connman-2766eed8b364475972cb0f2e306b6c3188877e1e.tar.bz2
connman-2766eed8b364475972cb0f2e306b6c3188877e1e.zip
ipconfig: Do not call inet_network() with a NULL pointer
inet_network() segfaults when given a NULL pointer as an argument.
Diffstat (limited to 'src')
-rw-r--r--src/ipconfig.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 1ce07e58..a872dff8 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);