summaryrefslogtreecommitdiff
path: root/src/provider.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2012-05-08 13:14:07 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-05-08 15:55:40 +0300
commitd22ad18e9c5541ab3ed2ae2b7392af1da214977d (patch)
tree640c334733caec503e917296e1d059328f6141d1 /src/provider.c
parent990eccc417dc72890e1f68e7309d765f4b184dab (diff)
downloadconnman-d22ad18e9c5541ab3ed2ae2b7392af1da214977d.tar.gz
connman-d22ad18e9c5541ab3ed2ae2b7392af1da214977d.tar.bz2
connman-d22ad18e9c5541ab3ed2ae2b7392af1da214977d.zip
provider: Fix network/netmask parsing and potential crash
Diffstat (limited to 'src/provider.c')
-rw-r--r--src/provider.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/provider.c b/src/provider.c
index a3604d49..3f4bb1cc 100644
--- a/src/provider.c
+++ b/src/provider.c
@@ -113,15 +113,25 @@ static void set_user_networks(struct connman_provider *provider,
while (networks[i] != NULL) {
char **elems = g_strsplit(networks[i], "/", 0);
- char *network, *netmask = NULL;
+ char *network, *netmask;
int family = PF_UNSPEC, ret;
if (elems == NULL)
break;
network = elems[0];
- if (elems[1] != NULL)
- netmask = elems[1];
+ if (network == NULL || *network == '\0') {
+ DBG("no network/netmask set");
+ g_strfreev(elems);
+ break;
+ }
+
+ netmask = elems[1];
+ if (netmask != NULL && *netmask == '\0') {
+ DBG("no netmask set");
+ g_strfreev(elems);
+ break;
+ }
if (g_strrstr(network, ":") != NULL)
family = AF_INET6;
@@ -132,7 +142,10 @@ static void set_user_networks(struct connman_provider *provider,
/* We have netmask length */
in_addr_t addr;
struct in_addr netmask_in;
- unsigned char prefix_len = atoi(netmask);
+ unsigned char prefix_len = 32;
+
+ if (netmask != NULL)
+ prefix_len = atoi(netmask);
addr = 0xffffffff << (32 - prefix_len);
netmask_in.s_addr = htonl(addr);