Skip to content

Commit 3a0b7fa

Browse files
qiyeliukuba-moo
authored andcommitted
selftests/net/ipsec: Fix Null pointer dereference in rtattr_pack()
Address Null pointer dereference / undefined behavior in rtattr_pack (note that size is 0 in the bad case). 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); ^ Signed-off-by: Liu Ye <liuye@kylinos.cn> Link: https://patch.msgid.link/20250116013037.29470-1-liuye@kylinos.cn Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 64ff63a commit 3a0b7fa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tools/testing/selftests/net/ipsec.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ static int rtattr_pack(struct nlmsghdr *nh, size_t req_sz,
227227

228228
attr->rta_len = RTA_LENGTH(size);
229229
attr->rta_type = rta_type;
230-
memcpy(RTA_DATA(attr), payload, size);
230+
if (payload)
231+
memcpy(RTA_DATA(attr), payload, size);
231232

232233
return 0;
233234
}

0 commit comments

Comments
 (0)