diff mbox series

[1/4] p2p: check connected peer before processing request

Message ID 20240301194056.1665549-1-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series [1/4] p2p: check connected peer before processing request | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-alpine-ci-fetch success Fetch PR
prestwoj/iwd-ci-fetch success Fetch PR
prestwoj/iwd-ci-gitlint success GitLint
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-alpine-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-alpine-ci-build success Build - Configure
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-alpine-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-alpine-ci-makecheck success Make Check
prestwoj/iwd-ci-incremental_build success Incremental Build with patches
prestwoj/iwd-alpine-ci-incremental_build success Incremental Build with patches
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

James Prestwood March 1, 2024, 7:40 p.m. UTC
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(-)

Comments

Denis Kenzior March 12, 2024, 3:10 a.m. UTC | #1
Hi James,

On 3/1/24 13:40, James Prestwood wrote:
> 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
diff mbox series

Patch

diff --git a/src/p2p.c b/src/p2p.c
index 08fe8444..205d4fcb 100644
--- a/src/p2p.c
+++ b/src/p2p.c
@@ -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 =