summaryrefslogtreecommitdiff
path: root/src/ipconfig.c
diff options
context:
space:
mode:
authorPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-04 16:37:54 +0200
committerPatrik Flykt <patrik.flykt@linux.intel.com>2013-02-05 13:29:26 +0200
commitb4374b8c280c003e4c322d6015b763f3917ef59f (patch)
tree5b0c3376dde766841e6b72aa85087287e71d0d83 /src/ipconfig.c
parentb5e3ef7c5448f78d28571ba2dcf9d10770324469 (diff)
downloadconnman-b4374b8c280c003e4c322d6015b763f3917ef59f.tar.gz
connman-b4374b8c280c003e4c322d6015b763f3917ef59f.tar.bz2
connman-b4374b8c280c003e4c322d6015b763f3917ef59f.zip
ipconfig: Add checks for invalid IPv4/IPv6 addresses
Also fine tune returned errors.
Diffstat (limited to 'src/ipconfig.c')
-rw-r--r--src/ipconfig.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/ipconfig.c b/src/ipconfig.c
index 824a3015..02b62986 100644
--- a/src/ipconfig.c
+++ b/src/ipconfig.c
@@ -1933,6 +1933,7 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
*privacy_string = NULL;
int prefix_length = 0, privacy = 0;
DBusMessageIter dict;
+ int type = -1;
DBG("ipconfig %p", ipconfig);
@@ -2021,7 +2022,7 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
case CONNMAN_IPCONFIG_METHOD_AUTO:
if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV6)
- return -EINVAL;
+ return -EOPNOTSUPP;
ipconfig->method = method;
if (privacy_string != NULL)
@@ -2030,7 +2031,26 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
break;
case CONNMAN_IPCONFIG_METHOD_MANUAL:
- if (address == NULL)
+ switch (ipconfig->type) {
+ case CONNMAN_IPCONFIG_TYPE_IPV4:
+ type = AF_INET;
+ break;
+ case CONNMAN_IPCONFIG_TYPE_IPV6:
+ type = AF_INET6;
+ break;
+ case CONNMAN_IPCONFIG_TYPE_UNKNOWN:
+ type = -1;
+ break;
+ }
+
+ if ((address != NULL && connman_inet_check_ipaddress(address)
+ != type) ||
+ (netmask != NULL &&
+ connman_inet_check_ipaddress(netmask)
+ != type) ||
+ (gateway != NULL &&
+ connman_inet_check_ipaddress(gateway)
+ != type))
return -EINVAL;
ipconfig->method = method;
@@ -2045,7 +2065,7 @@ int __connman_ipconfig_set_config(struct connman_ipconfig *ipconfig,
break;
case CONNMAN_IPCONFIG_METHOD_DHCP:
- if (ipconfig->type == CONNMAN_IPCONFIG_TYPE_IPV6)
+ if (ipconfig->type != CONNMAN_IPCONFIG_TYPE_IPV4)
return -EOPNOTSUPP;
ipconfig->method = method;