public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/bpf: Fix null pointer check in skb_pkt_end.c
@ 2025-04-22 18:23 Prabhav Kumar Vaish
  2025-04-22 22:15 ` Martin KaFai Lau
  0 siblings, 1 reply; 3+ messages in thread
From: Prabhav Kumar Vaish @ 2025-04-22 18:23 UTC (permalink / raw)
  To: ast, daniel, andrii, martin.lau, eddyz87, song, yonghong.song,
	john.fastabend, kpsingh, sdf, haoluo, jolsa, mykolal, shuah
  Cc: Prabhav Kumar Vaish, bpf, linux-kselftest, linux-kernel

Ensure that 'tcp' is checked for NULL before dereferencing. This resolves
a potential null pointer dereference warning reported by static analysis.

Signed-off-by: Prabhav Kumar Vaish <pvkumar5749404@gmail.com>
---
 tools/testing/selftests/bpf/progs/skb_pkt_end.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/progs/skb_pkt_end.c b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
index 3bb4451524a1..db33ff2839f7 100644
--- a/tools/testing/selftests/bpf/progs/skb_pkt_end.c
+++ b/tools/testing/selftests/bpf/progs/skb_pkt_end.c
@@ -45,10 +45,10 @@ int main_prog(struct __sk_buff *skb)
 		goto out;
 
 	tcp = (void*)(ip + 1);
-	if (tcp->dest != 0)
-		goto out;
 	if (!tcp)
 		goto out;
+	if (tcp->dest != 0)
+		goto out;
 
 	urg_ptr = tcp->urg_ptr;
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-23 17:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-22 18:23 [PATCH] selftests/bpf: Fix null pointer check in skb_pkt_end.c Prabhav Kumar Vaish
2025-04-22 22:15 ` Martin KaFai Lau
2025-04-23 17:58   ` [PATCH] selftests/bpf: Fix potential null pointer dereference " Prabhav Kumar Vaish

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox