[PATCH RFC bpf-next 01/15] samples: bpf: fix a couple of NULL dereferences

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When giving it just one ifname instead of two, it accesses argv[optind + 1],
which is out of bounds (as argc < optind + 1).

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
---
 samples/bpf/xdp_redirect_map_user.c | 4 ++--
 samples/bpf/xdp_redirect_user.c     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/samples/bpf/xdp_redirect_map_user.c b/samples/bpf/xdp_redirect_map_user.c
index 0e8192688dfc..ad3cdc4c07d3 100644
--- a/samples/bpf/xdp_redirect_map_user.c
+++ b/samples/bpf/xdp_redirect_map_user.c
@@ -169,8 +169,8 @@ int main(int argc, char **argv)
 		return 1;
 	}
 
-	if (optind == argc) {
-		printf("usage: %s <IFNAME|IFINDEX>_IN <IFNAME|IFINDEX>_OUT\n", argv[0]);
+	if (argc <= optind + 1) {
+		usage(basename(argv[0]));
 		return 1;
 	}
 
diff --git a/samples/bpf/xdp_redirect_user.c b/samples/bpf/xdp_redirect_user.c
index 41d705c3a1f7..4e310660632b 100644
--- a/samples/bpf/xdp_redirect_user.c
+++ b/samples/bpf/xdp_redirect_user.c
@@ -130,8 +130,8 @@ int main(int argc, char **argv)
 	if (!(xdp_flags & XDP_FLAGS_SKB_MODE))
 		xdp_flags |= XDP_FLAGS_DRV_MODE;
 
-	if (optind == argc) {
-		printf("usage: %s <IFNAME|IFINDEX>_IN <IFNAME|IFINDEX>_OUT\n", argv[0]);
+	if (argc <= optind + 1) {
+		usage(basename(argv[0]));
 		return 1;
 	}
 
-- 
2.31.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux