selftests/bpf: Fix possible NULL passed to memcpy() with zero size
authorAndrii Nakryiko <andrii@kernel.org>
Wed, 24 Nov 2021 00:23:20 +0000 (16:23 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Thu, 25 Nov 2021 23:15:03 +0000 (00:15 +0100)
Prevent sanitizer from complaining about passing NULL into memcpy(),
even if it happens with zero size.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20211124002325.1737739-9-andrii@kernel.org
tools/testing/selftests/bpf/prog_tests/core_reloc.c

index 1041d0c593f618729e93cce9fd5abc1730b3e35e..44a9868c70ea08a69877890ea033d48c98bb69b1 100644 (file)
@@ -881,7 +881,8 @@ void test_core_reloc(void)
                data = mmap_data;
 
                memset(mmap_data, 0, sizeof(*data));
-               memcpy(data->in, test_case->input, test_case->input_len);
+               if (test_case->input_len)
+                       memcpy(data->in, test_case->input, test_case->input_len);
                data->my_pid_tgid = my_pid_tgid;
 
                link = bpf_program__attach_raw_tracepoint(prog, tp_name);