[v1] app/regex: fix segfault in getopt_long call

Message ID 20201018142147.11456-1-ophirmu@nvidia.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v1] app/regex: fix segfault in getopt_long call |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional fail Functional Testing issues
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK

Commit Message

Ophir Munk Oct. 18, 2020, 2:21 p.m. UTC
  getopt_long() parses command-line arguments. One of its arguments
'longopts' is a pointer to the first element of an array of struct
option.  The last element of the array has to be filled with zeros
to mark the end of options. For example:

struct option longopts[] = {
{ "help",  0, 0, ARG_HELP},
....
/* End of options */
{ 0, 0, 0, 0 }
};

This commit adds the last element. Prior to this commit getopt_long()
continued parsing beyond the longopts[] array which occasionally caused
segmentation faults.

Fixes: de06137cb295 ("app/regex: add RegEx test application")
Cc: stable@dpdk.org

Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
---
 app/test-regex/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Ori Kam Oct. 19, 2020, 7:46 a.m. UTC | #1
Hi Ophir,

> -----Original Message-----
> From: Ophir Munk <ophirmu@nvidia.com>
> Sent: Sunday, October 18, 2020 5:22 PM
> Subject: [PATCH v1] app/regex: fix segfault in getopt_long call
> 
> getopt_long() parses command-line arguments. One of its arguments
> 'longopts' is a pointer to the first element of an array of struct
> option.  The last element of the array has to be filled with zeros
> to mark the end of options. For example:
> 
> struct option longopts[] = {
> { "help",  0, 0, ARG_HELP},
> ....
> /* End of options */
> { 0, 0, 0, 0 }
> };
> 
> This commit adds the last element. Prior to this commit getopt_long()
> continued parsing beyond the longopts[] array which occasionally caused
> segmentation faults.
> 
> Fixes: de06137cb295 ("app/regex: add RegEx test application")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
> ---
>  app/test-regex/main.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/app/test-regex/main.c b/app/test-regex/main.c
> index 0d35f45..e6080b4 100644
> --- a/app/test-regex/main.c
> +++ b/app/test-regex/main.c
> @@ -66,7 +66,9 @@ args_parse(int argc, char **argv, char *rules_file, char
> *data_file,
>  		/* Perf test only */
>  		{ "perf", 0, 0, ARG_PERF_MODE},
>  		/* Number of iterations to run with perf test */
> -		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS}
> +		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS},
> +		/* End of options */
> +		{ 0, 0, 0, 0 }
>  	};
> 
>  	argvopt = argv;
> --
> 2.8.4

Acked-by: Ori Kam <orika@nvidia.com>
Thanks,
Ori
  
Lukasz Wojciechowski Oct. 19, 2020, 8:13 a.m. UTC | #2
Hi,

W dniu 19.10.2020 o 09:46, Ori Kam pisze:
> Hi Ophir,
>
>> -----Original Message-----
>> From: Ophir Munk <ophirmu@nvidia.com>
>> Sent: Sunday, October 18, 2020 5:22 PM
>> Subject: [PATCH v1] app/regex: fix segfault in getopt_long call
>>
>> getopt_long() parses command-line arguments. One of its arguments
>> 'longopts' is a pointer to the first element of an array of struct
>> option.  The last element of the array has to be filled with zeros
>> to mark the end of options. For example:
>>
>> struct option longopts[] = {
>> { "help",  0, 0, ARG_HELP},
>> ....
>> /* End of options */
>> { 0, 0, 0, 0 }
>> };
>>
>> This commit adds the last element. Prior to this commit getopt_long()
>> continued parsing beyond the longopts[] array which occasionally caused
>> segmentation faults.
>>
>> Fixes: de06137cb295 ("app/regex: add RegEx test application")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
>> ---
>>   app/test-regex/main.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/app/test-regex/main.c b/app/test-regex/main.c
>> index 0d35f45..e6080b4 100644
>> --- a/app/test-regex/main.c
>> +++ b/app/test-regex/main.c
>> @@ -66,7 +66,9 @@ args_parse(int argc, char **argv, char *rules_file, char
>> *data_file,
>>   		/* Perf test only */
>>   		{ "perf", 0, 0, ARG_PERF_MODE},
>>   		/* Number of iterations to run with perf test */
>> -		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS}
>> +		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS},
>> +		/* End of options */
>> +		{ 0, 0, 0, 0 }
>>   	};
>>
>>   	argvopt = argv;
>> --
>> 2.8.4
> Acked-by: Ori Kam <orika@nvidia.com>
Acked-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
> Thanks,
> Ori

Best regards

Lukasz
  
Ophir Munk Oct. 19, 2020, 8:39 a.m. UTC | #3
Adding Thomas Monjalon
Thomas - when merging can you please remove the line: Cc: stable@dpdk.org ?

> -----Original Message-----
> From: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
> Sent: Monday, October 19, 2020 11:13 AM
> To: Ori Kam <orika@nvidia.com>; Ophir Munk <ophirmu@nvidia.com>;
> dev@dpdk.org; Raslan Darawsheh <rasland@nvidia.com>
> Cc: stable@dpdk.org; "'Lukasz Wojciechowski'",
> <l.wojciechow@partner.samsung.com>
> Subject: Re: [dpdk-dev] [PATCH v1] app/regex: fix segfault in getopt_long
> call
> 
> Hi,
> 
> W dniu 19.10.2020 o 09:46, Ori Kam pisze:
> > Hi Ophir,
> >
> >> -----Original Message-----
> >> From: Ophir Munk <ophirmu@nvidia.com>
> >> Sent: Sunday, October 18, 2020 5:22 PM
> >> Subject: [PATCH v1] app/regex: fix segfault in getopt_long call
> >>
> >> getopt_long() parses command-line arguments. One of its arguments
> >> 'longopts' is a pointer to the first element of an array of struct
> >> option.  The last element of the array has to be filled with zeros to
> >> mark the end of options. For example:
> >>
> >> struct option longopts[] = {
> >> { "help",  0, 0, ARG_HELP},
> >> ....
> >> /* End of options */
> >> { 0, 0, 0, 0 }
> >> };
> >>
> >> This commit adds the last element. Prior to this commit getopt_long()
> >> continued parsing beyond the longopts[] array which occasionally
> >> caused segmentation faults.
> >>
> >> Fixes: de06137cb295 ("app/regex: add RegEx test application")
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
> >> ---
> >>   app/test-regex/main.c | 4 +++-
> >>   1 file changed, 3 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/app/test-regex/main.c b/app/test-regex/main.c index
> >> 0d35f45..e6080b4 100644
> >> --- a/app/test-regex/main.c
> >> +++ b/app/test-regex/main.c
> >> @@ -66,7 +66,9 @@ args_parse(int argc, char **argv, char *rules_file,
> >> char *data_file,
> >>   		/* Perf test only */
> >>   		{ "perf", 0, 0, ARG_PERF_MODE},
> >>   		/* Number of iterations to run with perf test */
> >> -		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS}
> >> +		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS},
> >> +		/* End of options */
> >> +		{ 0, 0, 0, 0 }
> >>   	};
> >>
> >>   	argvopt = argv;
> >> --
> >> 2.8.4
> > Acked-by: Ori Kam <orika@nvidia.com>
> Acked-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
> > Thanks,
> > Ori
> 
> Best regards
> 
> Lukasz
> 
> --
> Lukasz Wojciechowski
> Principal Software Engineer
> 
> Samsung R&D Institute Poland
> Samsung Electronics
> Office +48 22 377 88 25
> l.wojciechow@partner.samsung.com
  
Thomas Monjalon Oct. 19, 2020, 10:05 p.m. UTC | #4
19/10/2020 10:39, Ophir Munk:
> Adding Thomas Monjalon
> Thomas - when merging can you please remove the line: Cc: stable@dpdk.org ?

No it should be kept because the bug is in a previous release.
  
Thomas Monjalon Oct. 19, 2020, 10:06 p.m. UTC | #5
> >> getopt_long() parses command-line arguments. One of its arguments
> >> 'longopts' is a pointer to the first element of an array of struct
> >> option.  The last element of the array has to be filled with zeros
> >> to mark the end of options. For example:
> >>
> >> struct option longopts[] = {
> >> { "help",  0, 0, ARG_HELP},
> >> ....
> >> /* End of options */
> >> { 0, 0, 0, 0 }
> >> };
> >>
> >> This commit adds the last element. Prior to this commit getopt_long()
> >> continued parsing beyond the longopts[] array which occasionally caused
> >> segmentation faults.
> >>
> >> Fixes: de06137cb295 ("app/regex: add RegEx test application")
> >> Cc: stable@dpdk.org
> >>
> >> Signed-off-by: Ophir Munk <ophirmu@nvidia.com>
> > Acked-by: Ori Kam <orika@nvidia.com>
> Acked-by: Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>

Applied, thanks
  

Patch

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 0d35f45..e6080b4 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -66,7 +66,9 @@  args_parse(int argc, char **argv, char *rules_file, char *data_file,
 		/* Perf test only */
 		{ "perf", 0, 0, ARG_PERF_MODE},
 		/* Number of iterations to run with perf test */
-		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS}
+		{ "nb_iter", 1, 0, ARG_NUM_OF_ITERATIONS},
+		/* End of options */
+		{ 0, 0, 0, 0 }
 	};
 
 	argvopt = argv;