Skip to content

Commit

Permalink
net: l2: wifi: Fix Print of SSID in WIFI scan result
Browse files Browse the repository at this point in the history
WIFI scan result shows junk character in SSID because of
the length of ssid is maximum(32 character) which leads
to buffer overflow. It required one character for null
terminator ‘\0’.

Signed-off-by: Kapil Bhatt <kapil.bhatt@nordicsemi.no>
  • Loading branch information
kapbh authored and fabiobaltieri committed Feb 8, 2024
1 parent a3cbf8e commit 2207fed
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion subsys/net/l2/wifi/wifi_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb)
(const struct wifi_scan_result *)cb->info;
uint8_t mac_string_buf[sizeof("xx:xx:xx:xx:xx:xx")];
const struct shell *sh = context.sh;
uint8_t ssid_print[WIFI_SSID_MAX_LEN + 1];

context.scan_result++;

Expand All @@ -115,8 +116,11 @@ static void handle_wifi_scan_result(struct net_mgmt_event_callback *cb)
"Num", "SSID", "(len)", "Chan (Band)", "RSSI", "Security", "BSSID", "MFP");
}

strncpy(ssid_print, entry->ssid, sizeof(ssid_print) - 1);
ssid_print[sizeof(ssid_print) - 1] = '\0';

PR("%-4d | %-32s %-5u | %-4u (%-6s) | %-4d | %-15s | %-17s | %-8s\n",
context.scan_result, entry->ssid, entry->ssid_length, entry->channel,
context.scan_result, ssid_print, entry->ssid_length, entry->channel,
wifi_band_txt(entry->band),
entry->rssi,
wifi_security_txt(entry->security),
Expand Down

0 comments on commit 2207fed

Please sign in to comment.