Skip to contentSkip to conversation

p2p: check connected peer before processing request

PATCH In review James Prestwood 2 participants 5 messages Mar 1, 2024 – Mar 12, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 p2p: check connected peer before processing request

Caught by static analysis, the dev->conn_peer pointer was being dereferenced very early on without a NULL check, but further it was being NULL checked. If there is a possibility of it being NULL the check should be done much earlier.

---
 src/p2p.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/p2p.c +4 -1
index 08fe8444..205d4fcb 100644
@@ -2310,6 +2310,9 @@ static void p2p_device_go_negotiation_req_cb(const struct mmpdu_header *mpdu,
 	if (!peer)
 		return;
 
+	if (!dev->conn_peer)
+		return;
+
 	if (body_len < 8)
 		return;
 
@@ -2438,7 +2441,7 @@ static void p2p_device_go_negotiation_req_cb(const struct mmpdu_header *mpdu,
 	memcpy(dev->conn_peer_interface_addr, req_info.intended_interface_addr,
 		6);
 
-	if (dev->is_go && dev->conn_peer) {
+	if (dev->is_go) {
 		p2p_set_group_id(dev);
 
 		dev->conn_config_delay =
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/4 eap-mschapv2: Check Password-Hash exists when loading settings

Caught by static analysis, the Password-Hash was never validated so it could end up memcpying from a NULL pointer.

---
 src/eap-mschapv2.c | 3 +++
 1 file changed, 3 insertions(+)
src/eap-mschapv2.c +3 -0
index ef0ce620..7f71cc82 100644
@@ -532,6 +532,9 @@ static bool eap_mschapv2_load_settings(struct eap_state *eap,
 		snprintf(setting, sizeof(setting), "%sPassword-Hash", prefix);
 		hash = l_settings_get_bytes(settings, "Security", setting,
 						&hash_len);
+		if (!hash)
+			goto error;
+
 		memcpy(state->password_hash, hash, 16);
 		explicit_bzero(hash, 16);
 		l_free(hash);
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/4 monitor: properly mask HE capabilities bitfield

In reply to James Prestwood

Caught by static analysis, the bitfield was incorrect and was masking 8 entries (0xff), not 5 (0x1f).

---
 monitor/nlmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/nlmon.c +1 -1
index bb8cd496..6fe63b8d 100644
@@ -1689,7 +1689,7 @@ static void print_ie_he_capabilities(unsigned int level,
 {
 	const uint8_t *ptr = data;
 	uint8_t width_set = bit_field((ptr + 6)[0], 1, 7);
-	uint8_t mask = 0xff;
+	uint8_t mask = 0x1f;
 
 	const char *he_channel_width_bitfield[] = {
 		[0] = "40MHz supported (2.4GHz)",
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/4 client: fix two issues caught by static analysis

In reply to James Prestwood

- va_end was not being called on an error condition
- An uninitialized struct was being accessed if ioctl failed

---
 client/display.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
client/display.c +4 -3
index 64125934..83214c86 100644
@@ -230,7 +230,8 @@ static void display_refresh_check_feasibility(void)
 {
 	const struct winsize ws;
 
-	ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws);
+	if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
+		return;
 
 	if (ws.ws_col < LINE_LEN - 1) {
 		if (display_refresh.enabled) {
@@ -564,8 +565,6 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
 		str += entry_append(e, str);
 	}
 
-	va_end(va);
-
 	display("%s\n", buf);
 	str = buf;
 
@@ -591,6 +590,8 @@ void display_table_row(const char *margin, unsigned int ncolumns, ...)
 	}
 
 done:
+	va_end(va);
+
 	for (i = 0; i < ncolumns; i++) {
 		if (entries[i].color)
 			l_free(entries[i].color);
Signature · 1 line
2.34.1
#4 lore raw
In reply to James Prestwood

Hi James,

Quoted 7 lines · James Prestwood

Caught by static analysis, the dev->conn_peer pointer was being dereferenced very early on without a NULL check, but further it was being NULL checked. If there is a possibility of it being NULL the check should be done much earlier.

---
  src/p2p.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

All applied, thanks.

Regards,
-Denis