Skip to content

Commit 6a2f9b6

Browse files
Loic Poulainnashif
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]> Signed-off-by: Flavio Ceolin <[email protected]>
1 parent 534c4ec commit 6a2f9b6

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
@@ -51,29 +51,30 @@ static int eswifi_reset(struct eswifi_dev *eswifi)
5151

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

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

60-
str++;
61-
while (*str && (*str != '"')) {
62-
*ssid++ = *str++;
58+
if (*str != '"') {
59+
return 0;
6360
}
61+
str++;
6462

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

6767
if (*str != '"') {
68-
return -EINVAL;
68+
return 0;
6969
}
7070

71-
return -EINVAL;
71+
return i;
7272
}
7373

7474
static void __parse_scan_res(char *str, struct wifi_scan_result *res)
7575
{
7676
int field = 0;
77+
int ret;
7778

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

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

9091
switch (++field) {
9192
case 1: /* SSID */
92-
__parse_ssid(str, res->ssid);
93-
res->ssid_length = strlen(res->ssid);
93+
res->ssid_length = __parse_ssid(str, res->ssid);
9494
str += res->ssid_length;
9595
break;
9696
case 2: /* mac addr */
@@ -179,7 +179,7 @@ static int __parse_ipv4_address(char *str, char *ssid, u8_t ip[4])
179179
unsigned int byte = -1;
180180

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

0 commit comments

Comments
 (0)