diff mbox series

Fix application of sizeof to pointer

Message ID 20211012111649.983253-1-davidcomponentone@gmail.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series Fix application of sizeof to pointer | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf fail VM_Test
bpf/vmtest-bpf-PR fail PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

David Yang Oct. 12, 2021, 11:16 a.m. UTC
From: David Yang <davidcomponentone@gmail.com>

The coccinelle check report:
"./samples/bpf/xdp_redirect_cpu_user.c:397:32-38:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: David Yang <davidcomponentone@gmail.com>
---
 samples/bpf/xdp_redirect_cpu_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Andrii Nakryiko Oct. 20, 2021, 5:55 p.m. UTC | #1
On Tue, Oct 12, 2021 at 4:17 AM <davidcomponentone@gmail.com> wrote:
>
> From: David Yang <davidcomponentone@gmail.com>
>
> The coccinelle check report:
> "./samples/bpf/xdp_redirect_cpu_user.c:397:32-38:
> ERROR: application of sizeof to pointer"
> Using the "strlen" to fix it.
>
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: David Yang <davidcomponentone@gmail.com>
> ---

For future submissions, please use [PATCH bpf-next] subject prefix.
For changes that are targeted against BPF samples, please use
samples/bpf: prefix as well. So in this case the patch subject should
have been something like:

[PATCH bpf-next] samples/bpf: Fix application of sizeof to pointer

I've fixed it up and applied to bpf-next, thanks.

>  samples/bpf/xdp_redirect_cpu_user.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
> index 6e25fba64c72..d84e6949007c 100644
> --- a/samples/bpf/xdp_redirect_cpu_user.c
> +++ b/samples/bpf/xdp_redirect_cpu_user.c
> @@ -325,7 +325,6 @@ int main(int argc, char **argv)
>         int add_cpu = -1;
>         int ifindex = -1;
>         int *cpu, i, opt;
> -       char *ifname;
>         __u32 qsize;
>         int n_cpus;
>
> @@ -393,9 +392,8 @@ int main(int argc, char **argv)
>                                 fprintf(stderr, "-d/--dev name too long\n");
>                                 goto end_cpu;
>                         }
> -                       ifname = (char *)&ifname_buf;
> -                       safe_strncpy(ifname, optarg, sizeof(ifname));
> -                       ifindex = if_nametoindex(ifname);
> +                       safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
> +                       ifindex = if_nametoindex(ifname_buf);
>                         if (!ifindex)
>                                 ifindex = strtoul(optarg, NULL, 0);
>                         if (!ifindex) {
> --
> 2.30.2
>
David Yang Oct. 21, 2021, 12:50 a.m. UTC | #2
OK, Thanks.

On Wed, Oct 20, 2021 at 10:55:27AM -0700, Andrii Nakryiko wrote:
> On Tue, Oct 12, 2021 at 4:17 AM <davidcomponentone@gmail.com> wrote:
> >
> > From: David Yang <davidcomponentone@gmail.com>
> >
> > The coccinelle check report:
> > "./samples/bpf/xdp_redirect_cpu_user.c:397:32-38:
> > ERROR: application of sizeof to pointer"
> > Using the "strlen" to fix it.
> >
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: David Yang <davidcomponentone@gmail.com>
> > ---
> 
> For future submissions, please use [PATCH bpf-next] subject prefix.
> For changes that are targeted against BPF samples, please use
> samples/bpf: prefix as well. So in this case the patch subject should
> have been something like:
> 
> [PATCH bpf-next] samples/bpf: Fix application of sizeof to pointer
> 
> I've fixed it up and applied to bpf-next, thanks.
> 
> >  samples/bpf/xdp_redirect_cpu_user.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
> > index 6e25fba64c72..d84e6949007c 100644
> > --- a/samples/bpf/xdp_redirect_cpu_user.c
> > +++ b/samples/bpf/xdp_redirect_cpu_user.c
> > @@ -325,7 +325,6 @@ int main(int argc, char **argv)
> >         int add_cpu = -1;
> >         int ifindex = -1;
> >         int *cpu, i, opt;
> > -       char *ifname;
> >         __u32 qsize;
> >         int n_cpus;
> >
> > @@ -393,9 +392,8 @@ int main(int argc, char **argv)
> >                                 fprintf(stderr, "-d/--dev name too long\n");
> >                                 goto end_cpu;
> >                         }
> > -                       ifname = (char *)&ifname_buf;
> > -                       safe_strncpy(ifname, optarg, sizeof(ifname));
> > -                       ifindex = if_nametoindex(ifname);
> > +                       safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
> > +                       ifindex = if_nametoindex(ifname_buf);
> >                         if (!ifindex)
> >                                 ifindex = strtoul(optarg, NULL, 0);
> >                         if (!ifindex) {
> > --
> > 2.30.2
> >
diff mbox series

Patch

diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
index 6e25fba64c72..d84e6949007c 100644
--- a/samples/bpf/xdp_redirect_cpu_user.c
+++ b/samples/bpf/xdp_redirect_cpu_user.c
@@ -325,7 +325,6 @@  int main(int argc, char **argv)
 	int add_cpu = -1;
 	int ifindex = -1;
 	int *cpu, i, opt;
-	char *ifname;
 	__u32 qsize;
 	int n_cpus;
 
@@ -393,9 +392,8 @@  int main(int argc, char **argv)
 				fprintf(stderr, "-d/--dev name too long\n");
 				goto end_cpu;
 			}
-			ifname = (char *)&ifname_buf;
-			safe_strncpy(ifname, optarg, sizeof(ifname));
-			ifindex = if_nametoindex(ifname);
+			safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
+			ifindex = if_nametoindex(ifname_buf);
 			if (!ifindex)
 				ifindex = strtoul(optarg, NULL, 0);
 			if (!ifindex) {