Skip to content

Commit 1c9b37a

Browse files
rlubosjgl-meta
authored andcommitted
net: wifi_shell: Add user input validation for SSID and PSK
When parsing user input for "wifi connect" and "wifi ap enable" commands, the SSID and PSK lengths were not verified. It's better to detect invalid connect/AP enable parameters early, so that help text can be printed, instead of letting wifi_mgmt command to fail. For WIFI_SECURITY_TYPE_SAE, follow the Linux convention of limiting the size to 128 bytes. Signed-off-by: Robert Lubos <[email protected]> (cherry picked from commit 30382da)
1 parent 119253c commit 1c9b37a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

include/zephyr/net/wifi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ static inline const char *wifi_band_txt(enum wifi_frequency_bands band)
123123
}
124124

125125
#define WIFI_SSID_MAX_LEN 32
126+
#define WIFI_PSK_MIN_LEN 8
126127
#define WIFI_PSK_MAX_LEN 64
128+
#define WIFI_SAE_PSWD_MAX_LEN 128
127129
#define WIFI_MAC_ADDR_LEN 6
128130

129131
#define WIFI_CHANNEL_MAX 233

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
326326
/* SSID */
327327
params->ssid = argv[0];
328328
params->ssid_length = strlen(params->ssid);
329+
if (params->ssid_length > WIFI_SSID_MAX_LEN) {
330+
return -EINVAL;
331+
}
329332

330333
/* Channel (optional) */
331334
if ((idx < argc) && (strlen(argv[idx]) <= 3)) {
@@ -371,6 +374,14 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
371374
idx++;
372375
}
373376
}
377+
378+
if (params->psk_length < WIFI_PSK_MIN_LEN ||
379+
(params->security != WIFI_SECURITY_TYPE_SAE &&
380+
params->psk_length > WIFI_PSK_MAX_LEN) ||
381+
(params->security == WIFI_SECURITY_TYPE_SAE &&
382+
params->psk_length > WIFI_SAE_PSWD_MAX_LEN)) {
383+
return -EINVAL;
384+
}
374385
} else {
375386
params->security = WIFI_SECURITY_TYPE_NONE;
376387
}

0 commit comments

Comments
 (0)