Added patch to prevent user from erroneously passing negative numbers to hackbench. Resolves: RHEL-36745 Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
		
			
				
	
	
		
			71 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			Diff
		
	
	
	
	
	
| From cadd661f984c0e6717e681fdaca1ce589b0ed964 Mon Sep 17 00:00:00 2001
 | |
| From: Anubhav Shelat <ashelat@redhat.com>
 | |
| Date: Wed, 22 May 2024 10:43:47 -0400
 | |
| Subject: [PATCH 2/2] rt-tests: hackbench: properly recognize when integer
 | |
|  arguments are negative
 | |
| 
 | |
| hackbench is supposed to catch when the user passes
 | |
| negative arguments to options -f, -g, -l, and -s.
 | |
| 
 | |
| Previously hackbench would allow options to accept
 | |
| negative arguments, resulting in undefined behavior.
 | |
| 
 | |
| Now process_options() assigns variables outside of
 | |
| the if considiton where they are used. hackbench will
 | |
| output a usage message if the user inputs a negative
 | |
| argument.
 | |
| 
 | |
| Signed-off-by: Anubhav Shelat <ashelat@redhat.com>
 | |
| Signed-off-by: John Kacur <jkacur@redhat.com>
 | |
| ---
 | |
|  src/hackbench/hackbench.c | 12 ++++++++----
 | |
|  1 file changed, 8 insertions(+), 4 deletions(-)
 | |
| 
 | |
| diff --git a/src/hackbench/hackbench.c b/src/hackbench/hackbench.c
 | |
| index fec8357bef81..55be325a38df 100644
 | |
| --- a/src/hackbench/hackbench.c
 | |
| +++ b/src/hackbench/hackbench.c
 | |
| @@ -426,7 +426,8 @@ static void process_options(int argc, char *argv[])
 | |
|  		}
 | |
|  		switch (c) {
 | |
|  		case 'f':
 | |
| -			if ((num_fds = atoi(optarg)) <= 0) {
 | |
| +			num_fds = atoi(optarg);
 | |
| +			if (atoi(optarg) <= 0) {
 | |
|  				fprintf(stderr, "%s: --fds|-f requires an integer > 0\n", argv[0]);
 | |
|  				print_usage_exit(1);
 | |
|  			}
 | |
| @@ -435,7 +436,8 @@ static void process_options(int argc, char *argv[])
 | |
|  			fifo = 1;
 | |
|  			break;
 | |
|  		case 'g':
 | |
| -			if ((num_groups = atoi(optarg)) <= 0) {
 | |
| +			num_groups = atoi(optarg);
 | |
| +			if (atoi(optarg) <= 0) {
 | |
|  				fprintf(stderr, "%s: --groups|-g requires an integer > 0\n", argv[0]);
 | |
|  				print_usage_exit(1);
 | |
|  			}
 | |
| @@ -444,7 +446,8 @@ static void process_options(int argc, char *argv[])
 | |
|  			print_usage_exit(0);
 | |
|  			break;
 | |
|  		case 'l':
 | |
| -			if ((loops = atoi(optarg)) <= 0) {
 | |
| +			loops = atoi(optarg);
 | |
| +			if (atoi(optarg) <= 0) {
 | |
|  				fprintf(stderr, "%s: --loops|-l requires an integer > 0\n", argv[0]);
 | |
|  				print_usage_exit(1);
 | |
|  			}
 | |
| @@ -456,7 +459,8 @@ static void process_options(int argc, char *argv[])
 | |
|  			use_inet = 1;
 | |
|  			break;
 | |
|  		case 's':
 | |
| -			if ((datasize = atoi(optarg)) <= 0) {
 | |
| +			datasize = atoi(optarg);
 | |
| +			if (atoi(optarg) <= 0) {
 | |
|  				fprintf(stderr, "%s: --datasize|-s requires an integer > 0\n", argv[0]);
 | |
|  				print_usage_exit(1);
 | |
|  			}
 | |
| -- 
 | |
| 2.45.1
 | |
| 
 |