Skip to content

Commit 2453afe

Browse files
kkdwvdAlexei Starovoitov
authored andcommitted
samples/bpf: Fix incorrect use of strlen in xdp_redirect_cpu
Commit b599015 ("samples/bpf: Fix application of sizeof to pointer") tried to fix a bug where sizeof was incorrectly applied to a pointer instead of the array string was being copied to, to find the destination buffer size, but ended up using strlen, which is still incorrect. However, on closer look ifname_buf has no other use, hence directly use optarg. Fixes: b599015 ("samples/bpf: Fix application of sizeof to pointer") Fixes: e531a22 ("samples: bpf: Convert xdp_redirect_cpu to XDP samples helper") Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Alexander Lobakin <alexandr.lobakin@intel.com> Tested-by: Alexander Lobakin <alexandr.lobakin@intel.com> Link: https://lore.kernel.org/bpf/20211112020301.528357-1-memxor@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent e4ac80e commit 2453afe

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎samples/bpf/xdp_redirect_cpu_user.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ int main(int argc, char **argv)
309309
const char *mprog_filename = NULL, *mprog_name = NULL;
310310
struct xdp_redirect_cpu *skel;
311311
struct bpf_map_info info = {};
312-
char ifname_buf[IF_NAMESIZE];
313312
struct bpf_cpumap_val value;
314313
__u32 infosz = sizeof(info);
315314
int ret = EXIT_FAIL_OPTION;
@@ -390,10 +389,10 @@ int main(int argc, char **argv)
390389
case 'd':
391390
if (strlen(optarg) >= IF_NAMESIZE) {
392391
fprintf(stderr, "-d/--dev name too long\n");
392+
usage(argv, long_options, __doc__, mask, true, skel->obj);
393393
goto end_cpu;
394394
}
395-
safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
396-
ifindex = if_nametoindex(ifname_buf);
395+
ifindex = if_nametoindex(optarg);
397396
if (!ifindex)
398397
ifindex = strtoul(optarg, NULL, 0);
399398
if (!ifindex) {

0 commit comments

Comments
 (0)