Skip to content

Commit c06f126

Browse files
committed
mctp-netlink: Don't memcpy() when source list is NULL
Mitigate the ubsan splat: Feb 27 09:30:55 test mctpd[984]: SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ../../../../../../workspace/sources/mctp/src/mctp-netlink.c:1102:2 in Feb 27 09:31:00 test mctpd[993]: ../../../../../../workspace/sources/mctp/src/mctp-netlink.c:1102:2: runtime error: null pointer passed as argument 2, which is declared to never be null Feb 27 09:31:00 test mctpd[993]: #0 0x47fcc0 (/usr/sbin/mctpd+0x57cc0) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda) Feb 27 09:31:00 test mctpd[993]: #1 0x459590 (/usr/sbin/mctpd+0x31590) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda) Feb 27 09:31:00 test mctpd[993]: #2 0x4498f0 (/usr/sbin/mctpd+0x218f0) (BuildId: 74658a0b3317f1295bab6bbcd8febf809768bfda) Feb 27 09:31:00 test mctpd[993]: #3 0xa62904ac (/usr/lib/libc.so.6+0x1f4ac) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b) Feb 27 09:31:00 test mctpd[993]: #4 0xa6290598 in __libc_start_main (/usr/lib/libc.so.6+0x1f598) (BuildId: f7dfc12cfaed3ca290b3c7f41ef9145c0de0fe6b) Signed-off-by: Andrew Jeffery <[email protected]>
1 parent 7c28dad commit c06f126

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/mctp-netlink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,11 +1094,12 @@ mctp_eid_t *mctp_nl_addrs_byindex(const mctp_nl *nl, int index, size_t *ret_num)
10941094
mctp_eid_t *ret;
10951095

10961096
*ret_num = 0;
1097-
if (!entry)
1097+
if (!entry || entry->num_local == 0)
10981098
return NULL;
10991099
ret = malloc(entry->num_local);
11001100
if (!ret)
11011101
return NULL;
1102+
assert(entry->local_eids);
11021103
memcpy(ret, entry->local_eids, entry->num_local);
11031104
*ret_num = entry->num_local;
11041105
return ret;

0 commit comments

Comments
 (0)