From: Patrik Flykt Date: Mon, 4 Feb 2013 14:37:54 +0000 (+0200) Subject: ipconfig: Add checks for invalid IPv4/IPv6 addresses X-Git-Tag: 1.12~132 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b4374b8c280c003e4c322d6015b763f3917ef59f;p=platform%2Fupstream%2Fconnman.git ipconfig: Add checks for invalid IPv4/IPv6 addresses Also fine tune returned errors. --- diff --git a/src/ipconfig.c b/src/ipconfig.c index 824a301..02b6298 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;