Skip to content

Commit 0a75809

Browse files
jukkarmmahadevan108
authored andcommitted
net: wifi: mgmt: Check string length in sscanf
Make sure we are not able to overwrite string variables in sscanf call. Allocate also one extra byte for null terminator character. Fixes #80644 Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
1 parent 5249619 commit 0a75809

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL);
2323

2424
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_ROAMING
2525
#define MAX_NEIGHBOR_AP_LIMIT 6U
26-
#define MAX_EVENT_STR_LEN 32U
26+
#define MAX_EVENT_STR_LEN 32
2727

2828
struct wifi_rrm_neighbor_ap_t {
2929
char ssid[WIFI_SSID_MAX_LEN + 1];
@@ -502,16 +502,21 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_NEIGHBOR_REP_COMPLETE,
502502
void wifi_mgmt_raise_neighbor_rep_recv_event(struct net_if *iface, char *inbuf, size_t buf_len)
503503
{
504504
const uint8_t *buf = inbuf;
505-
char event[MAX_EVENT_STR_LEN] = {0};
506-
char bssid[WIFI_SSID_MAX_LEN] = {0};
507-
char bssid_info[WIFI_SSID_MAX_LEN] = {0};
505+
char event[MAX_EVENT_STR_LEN + 1] = {0};
506+
char bssid[WIFI_SSID_MAX_LEN + 1] = {0};
507+
char bssid_info[WIFI_SSID_MAX_LEN + 1] = {0};
508508
int op_class, channel, phy_type;
509509
int idx = roaming_params.neighbor_rep.neighbor_cnt;
510510

511511
if (!buf || buf[0] == '\0') {
512512
return;
513513
}
514-
if (sscanf(buf, "%s bssid=%s info=%s op_class=%d chan=%d phy_type=%d",
514+
515+
if (sscanf(buf,
516+
"%" STRINGIFY(MAX_EVENT_STR_LEN) "s "
517+
"bssid=%" STRINGIFY(WIFI_SSID_MAX_LEN) "s "
518+
"info=%" STRINGIFY(WIFI_SSID_MAX_LEN) "s "
519+
"op_class=%d chan=%d phy_type=%d",
515520
event, bssid, bssid_info, &op_class, &channel, &phy_type) == 6) {
516521
int i;
517522
int match = 0;

0 commit comments

Comments
 (0)