Skip to content

Commit c9363a9

Browse files
krish2718carlescufi
authored andcommitted
wifi: shell: Fix the channel extraction
The channel extraction from string directly uses the end variable with limited data type, this causes issue if an invalid channel that exceeds the data is given as an input e.g., 300, which would end up as a valid channel 44. Use an intermediate variable with type that can hold all possible combinations (valid and invalid) and only after validation assign that to the end type. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 2f88df9 commit c9363a9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

subsys/net/l2/wifi/wifi_shell.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,13 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
466466

467467
/* Channel (optional: STA, mandatory: AP) */
468468
if ((idx < argc) && (strlen(argv[idx]) <= 3)) {
469-
params->channel = strtol(argv[idx], &endptr, 10);
469+
long channel = strtol(argv[idx], &endptr, 10);
470+
470471
if (*endptr != '\0') {
471472
return -EINVAL;
472473
}
473474

474-
if (iface_mode == WIFI_MODE_INFRA && params->channel == 0) {
475+
if (iface_mode == WIFI_MODE_INFRA && channel == 0) {
475476
params->channel = WIFI_CHANNEL_ANY;
476477
} else {
477478
const uint8_t bands[] = {WIFI_FREQ_BAND_2_4_GHZ,
@@ -482,7 +483,7 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
482483

483484
for (band = 0; band < ARRAY_SIZE(bands); band++) {
484485
if (wifi_utils_validate_chan(bands[band],
485-
params->channel)) {
486+
channel)) {
486487
found = true;
487488
break;
488489
}
@@ -491,8 +492,9 @@ static int __wifi_args_to_params(size_t argc, char *argv[],
491492
if (!found) {
492493
return -EINVAL;
493494
}
494-
}
495495

496+
params->channel = channel;
497+
}
496498
idx++;
497499
}
498500

0 commit comments

Comments
 (0)