AF_XDP-interaction: Fix strncpy warning in common_user_bpf_xdp.c

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
This commit is contained in:
Jesper Dangaard Brouer
2021-10-28 14:20:14 +02:00
parent 45a7e3cab7
commit 9ef9104c61

View File

@ -239,6 +239,7 @@ struct bpf_object *load_bpf_and_xdp_attach(struct config *cfg)
struct bpf_object *bpf_obj;
int offload_ifindex = 0;
int prog_fd = -1;
size_t len;
int err;
/* If flags indicate hardware offload, supply ifindex */
@ -274,8 +275,9 @@ struct bpf_object *load_bpf_and_xdp_attach(struct config *cfg)
exit(EXIT_FAIL_BPF);
}
strncpy(cfg->progsec, bpf_program__section_name(bpf_prog),
sizeof(cfg->progsec));
len = sizeof(cfg->progsec) - 1;
strncpy(cfg->progsec, bpf_program__section_name(bpf_prog), len);
cfg->progsec[len] = '\0'; /* null terminate string */
prog_fd = bpf_program__fd(bpf_prog);
if (prog_fd <= 0) {