Use strtol to identify invalid input before setting subnet_mask 95/259695/4
authorNishant Chaprana <n.chaprana@samsung.com>
Fri, 11 Jun 2021 06:38:10 +0000 (12:08 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Tue, 15 Jun 2021 03:33:41 +0000 (09:03 +0530)
Change-Id: I7ebddac6fd4a5808baa15de4e59d7a575485cc00
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
src/wifi_ap.c

index 9a765a18d517c5839c4f56b732b3e27172f6a2c1..aff594bca1a7d65d2526c93f5932bc4948e39e1d 100755 (executable)
@@ -1083,8 +1083,35 @@ EXPORT_API int wifi_manager_ap_set_subnet_mask(wifi_manager_ap_h ap,
                        /* 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 {