sta_ip_config: Fix potential NULL pointer dereference error
"ip" and "mask" values fetched by cmd_sta_set_ip_config() can be NULL.
This could lead to NULL pointer dereference in case of IPv6. The
original IPv4-only implementation used to check the values before
proceeding, but that was broken when IPv6 support was added. Fix this by
restoring NULL checks before proceeding for all cases.
Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
diff --git a/sta.c b/sta.c
index 0ff28cc..e2a1c33 100644
--- a/sta.c
+++ b/sta.c
@@ -794,7 +794,18 @@
}
ip = get_param(cmd, "ip");
+ if (!ip) {
+ send_resp(dut, conn, SIGMA_INVALID,
+ "ErrorCode,Missing IP address");
+ return 0;
+ }
+
mask = get_param(cmd, "mask");
+ if (!mask) {
+ send_resp(dut, conn, SIGMA_INVALID,
+ "ErrorCode,Missing subnet mask");
+ return 0;
+ }
if (type == 2) {
int net = atoi(mask);
@@ -839,8 +850,7 @@
static_ip_file(6, ip, mask, NULL);
return 1;
} else if (type == 1) {
- if (ip == NULL || !is_ip_addr(ip) ||
- mask == NULL || !is_ip_addr(mask))
+ if (!is_ip_addr(ip) || !is_ip_addr(mask))
return -1;
}