Skip to content

Commit 40e2d94

Browse files
Loic Poulainjukkar
Loic Poulain
authored andcommitted
drivers: wifi: eswifi: Fix parsing buffer-overflows
There are possible buffer overflows when parsing the ip address and SSID. Ensure that we never overwrite the ip and SSID buffers. Signed-off-by: Loic Poulain <[email protected]>
1 parent e7c4d29 commit 40e2d94

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/wifi/eswifi/eswifi_core.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,30 @@ static int eswifi_reset(struct eswifi_dev *eswifi)
5252

5353
static inline int __parse_ssid(char *str, char *ssid)
5454
{
55-
/* fnt => '"SSID"' */
55+
int i = 0;
5656

57-
if (!*str || (*str != '"')) {
58-
return -EINVAL;
59-
}
57+
/* fmt => "SSID" */
6058

61-
str++;
62-
while (*str && (*str != '"')) {
63-
*ssid++ = *str++;
59+
if (*str != '"') {
60+
return 0;
6461
}
62+
str++;
6563

66-
*ssid = '\0';
64+
while (*str && (*str != '"') && i < WIFI_SSID_MAX_LEN) {
65+
ssid[i++] = *str++;
66+
}
6767

6868
if (*str != '"') {
69-
return -EINVAL;
69+
return 0;
7070
}
7171

72-
return -EINVAL;
72+
return i;
7373
}
7474

7575
static void __parse_scan_res(char *str, struct wifi_scan_result *res)
7676
{
7777
int field = 0;
78+
int ret;
7879

7980
/* fmt => #001,"SSID",MACADDR,RSSI,BITRATE,MODE,SECURITY,BAND,CHANNEL */
8081

@@ -90,8 +91,7 @@ static void __parse_scan_res(char *str, struct wifi_scan_result *res)
9091

9192
switch (++field) {
9293
case 1: /* SSID */
93-
__parse_ssid(str, res->ssid);
94-
res->ssid_length = strlen(res->ssid);
94+
res->ssid_length = __parse_ssid(str, res->ssid);
9595
str += res->ssid_length;
9696
break;
9797
case 2: /* mac addr */
@@ -180,7 +180,7 @@ static int __parse_ipv4_address(char *str, char *ssid, uint8_t ip[4])
180180
unsigned int byte = -1;
181181

182182
/* fmt => [JOIN ] SSID,192.168.2.18,0,0 */
183-
while (*str) {
183+
while (*str && byte < 4) {
184184
if (byte == -1) {
185185
if (!strncmp(str, ssid, strlen(ssid))) {
186186
byte = 0U;

0 commit comments

Comments
 (0)