/* subnet mask provided as input parameter is a string
* while for IPv6 address subnet mask in prefix length
* which should be in integer form */
- profile_info->net_info.PrefixLen6 =
- atoi(subnet_mask) ;
+ long val;
+ char *endptr;
+
+ errno = 0;
+
+ val = strtol(subnet_mask, &endptr, 10);
+ if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN))
+ || (errno != 0 && val == 0)) {
+ WIFI_LOG(WIFI_ERROR, "invalid subnet mask");
+ __NETWORK_CAPI_FUNC_EXIT__;
+ return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+ }
+
+ if (endptr == subnet_mask) {
+ WIFI_LOG(WIFI_ERROR, "invalid subnet mask");
+ __NETWORK_CAPI_FUNC_EXIT__;
+ return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+ }
+
+ if (*endptr != '\0')
+ WIFI_LOG(WIFI_WARN, "Further characters after number in subnet_mask: %s\n", endptr);
+
+ if (val < 0 || val > 128) {
+ WIFI_LOG(WIFI_ERROR, "invalid subnet mask");
+ __NETWORK_CAPI_FUNC_EXIT__;
+ return WIFI_MANAGER_ERROR_INVALID_PARAMETER;
+ }
+
+ profile_info->net_info.PrefixLen6 = val;
}
//LCOV_EXCL_STOP
} else {