Patchwork samples: bpf: user proper argument index

login
register
mail settings
Submitter Ioana Ciornei
Date Jan. 9, 2019, 5:06 p.m.
Message ID <1547053600-13817-1-git-send-email-ioana.ciornei@nxp.com>
Download mbox | patch
Permalink /patch/696071/
State New
Headers show

Comments

Ioana Ciornei - Jan. 9, 2019, 5:06 p.m.
Use optind as index for argv instead of a hardcoded value.
When the program has options this leads to improper parameter handling.

Fixes: dc378a1ab5b6 ("samples: bpf: get ifindex from ifname")

Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
---
 samples/bpf/xdp1_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Matteo Croce - Jan. 9, 2019, 11:25 p.m.
On Wed, Jan 9, 2019 at 5:07 PM Ioana Ciornei <ioana.ciornei@nxp.com> wrote:
>
> Use optind as index for argv instead of a hardcoded value.
> When the program has options this leads to improper parameter handling.
>
> Fixes: dc378a1ab5b6 ("samples: bpf: get ifindex from ifname")
>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>
> ---
>  samples/bpf/xdp1_user.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
> index 0a197f8..8bfda95 100644
> --- a/samples/bpf/xdp1_user.c
> +++ b/samples/bpf/xdp1_user.c
> @@ -103,7 +103,7 @@ int main(int argc, char **argv)
>                 return 1;
>         }
>
> -       ifindex = if_nametoindex(argv[1]);
> +       ifindex = if_nametoindex(argv[optind]);
>         if (!ifindex) {
>                 perror("if_nametoindex");
>                 return 1;
> --
> 1.9.1
>

ACK
Daniel Borkmann - Jan. 10, 2019, 2:59 p.m.
On 01/09/2019 06:06 PM, Ioana Ciornei wrote:
> Use optind as index for argv instead of a hardcoded value.
> When the program has options this leads to improper parameter handling.
> 
> Fixes: dc378a1ab5b6 ("samples: bpf: get ifindex from ifname")
> 
> Signed-off-by: Ioana Ciornei <ioana.ciornei@nxp.com>

Applied to bpf, thanks!

Patch

diff --git a/samples/bpf/xdp1_user.c b/samples/bpf/xdp1_user.c
index 0a197f8..8bfda95 100644
--- a/samples/bpf/xdp1_user.c
+++ b/samples/bpf/xdp1_user.c
@@ -103,7 +103,7 @@  int main(int argc, char **argv)
 		return 1;
 	}
 
-	ifindex = if_nametoindex(argv[1]);
+	ifindex = if_nametoindex(argv[optind]);
 	if (!ifindex) {
 		perror("if_nametoindex");
 		return 1;