[2/2] samples/bpf: test_cgrp2_sock2: fix an off by one
diff mbox series

Message ID 20180713150301.gdvfu2ejlzlnglii@kili.mountain
State Accepted, archived
Delegated to: BPF Maintainers
Headers show
Series
  • [1/2] samples: bpf: ensure that we don't load over MAX_PROGS programs
Related show

Commit Message

Dan Carpenter July 13, 2018, 3:05 p.m. UTC
"prog_cnt" is the number of elements which are filled out in prog_fd[]
so the test should be >= instead of >.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

David Ahern July 13, 2018, 3:17 p.m. UTC | #1
On 7/13/18 11:05 AM, Dan Carpenter wrote:
> "prog_cnt" is the number of elements which are filled out in prog_fd[]
> so the test should be >= instead of >.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 

Fixes: 554ae6e792ef3 ("samples/bpf: add userspace example for
prohibiting sockets")
Reviewed-by: David Ahern <dsahern@gmail.com>

Thanks for the fix.
Alexei Starovoitov July 16, 2018, 10:07 p.m. UTC | #2
On Fri, Jul 13, 2018 at 06:05:37PM +0300, Dan Carpenter wrote:
> "prog_cnt" is the number of elements which are filled out in prog_fd[]
> so the test should be >= instead of >.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

since this is sample code I've applied both patches to bpf-next tree.
Thanks

Patch
diff mbox series

diff --git a/samples/bpf/test_cgrp2_sock2.c b/samples/bpf/test_cgrp2_sock2.c
index 3b5be2364975..a9277b118c33 100644
--- a/samples/bpf/test_cgrp2_sock2.c
+++ b/samples/bpf/test_cgrp2_sock2.c
@@ -51,7 +51,7 @@  int main(int argc, char **argv)
 	if (argc > 3)
 		filter_id = atoi(argv[3]);
 
-	if (filter_id > prog_cnt) {
+	if (filter_id >= prog_cnt) {
 		printf("Invalid program id; program not found in file\n");
 		return EXIT_FAILURE;
 	}