public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net V3] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack()
@ 2025-01-16  1:30 Liu Ye
  2025-01-20 19:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Ye @ 2025-01-16  1:30 UTC (permalink / raw)
  To: horms, kuba, steffen.klassert, herbert, davem, edumazet, pabeni,
	shuah
  Cc: netdev, linux-kernel, linux-kselftest, Liu Ye

From: Liu Ye <liuye@kylinos.cn>

Address Null pointer dereference in rtattr_pack.

Flagged by cppcheck as:
    tools/testing/selftests/net/ipsec.c:230:25: warning: Possible null pointer
    dereference: payload [nullPointer]
    memcpy(RTA_DATA(attr), payload, size);
                           ^
    tools/testing/selftests/net/ipsec.c:1618:54: note: Calling function 'rtattr_pack',
    4th argument 'NULL' value is 0
    if (rtattr_pack(&req.nh, sizeof(req), XFRMA_IF_ID, NULL, 0)) {
                                                       ^
    tools/testing/selftests/net/ipsec.c:230:25: note: Null pointer dereference
    memcpy(RTA_DATA(attr), payload, size);
                           ^
Fixes: 70bfdf62e93a ("selftests/net/ipsec: Add test for xfrm_spdattr_type_t")
Signed-off-by: Liu Ye <liuye@kylinos.cn>
---
V3: Remove the redundant from.
    Sign-off after fixes.
V2: Modify description.
    Add code checking tools.
    Separating family and given name in Signed-off-by line.
    Modify code format.
    Add fixes.
---
---
 tools/testing/selftests/net/ipsec.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/ipsec.c b/tools/testing/selftests/net/ipsec.c
index be4a30a0d02a..9b44a091802c 100644
--- a/tools/testing/selftests/net/ipsec.c
+++ b/tools/testing/selftests/net/ipsec.c
@@ -227,7 +227,8 @@ static int rtattr_pack(struct nlmsghdr *nh, size_t req_sz,
 
 	attr->rta_len = RTA_LENGTH(size);
 	attr->rta_type = rta_type;
-	memcpy(RTA_DATA(attr), payload, size);
+	if (payload)
+		memcpy(RTA_DATA(attr), payload, size);
 
 	return 0;
 }
-- 
2.25.1


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

end of thread, other threads:[~2025-01-20 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-16  1:30 [PATCH net V3] selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack() Liu Ye
2025-01-20 19:50 ` patchwork-bot+netdevbpf

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