Skip to contentSkip to conversation

app/regex: fix segfault in getopt_long call

PATCH Applied Ophir Munk 4 participants 6 messages Oct 18, 2020 – Oct 19, 2020

lore
Share & tools
lore

Ophir Munk

author
#0 lore raw

PATCH 1/1 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")
---
 app/test-regex/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
app/test-regex/main.c +3 -1
index 0d35f45..e6080b4 100644
@@ -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;
Signature · 1 line
2.8.4
Acked-by on v1 1/1
#1 lore raw

Hi Ophir,

Quoted 44 lines

-----Original Message-----
From: Ophir Munk <[email protected]>
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")
---
 app/test-regex/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
app/test-regex/main.c +3 -1
index 0d35f45..e6080b4 100644
@@ -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 }
 	};
 
Quoted 3 lines

argvopt = argv;
--
2.8.4

Thanks,
Ori

#2 lore raw

Hi,

W dniu 19.10.2020 o 09:46, Ori Kam pisze:

Quoted 46 lines

Hi Ophir,

Quoted 44 lines

-----Original Message-----
From: Ophir Munk <[email protected]>
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")
---
  app/test-regex/main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
app/test-regex/main.c +3 -1
index 0d35f45..e6080b4 100644
@@ -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 }
  	};
 
Quoted 4 lines
Quoted 3 lines

argvopt = argv;
--
2.8.4

Quoted 2 lines

Thanks,
Ori

Best regards

Lukasz

Signature · 7 lines
Lukasz Wojciechowski
Principal Software Engineer

Samsung R&D Institute Poland
Samsung Electronics
Office +48 22 377 88 25
[email protected]
author
#3 lore raw

Adding Thomas Monjalon
Thomas - when merging can you please remove the line: Cc: [email protected] ?

Quoted 79 lines

-----Original Message-----
From: Lukasz Wojciechowski <[email protected]>
Sent: Monday, October 19, 2020 11:13 AM
To: Ori Kam <[email protected]>; Ophir Munk <[email protected]>; [email protected]; Raslan Darawsheh <[email protected]>
Cc: [email protected]; "'Lukasz Wojciechowski'", <[email protected]>
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:

Quoted 46 lines

Hi Ophir,

Quoted 44 lines

-----Original Message-----
From: Ophir Munk <[email protected]>
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")
---
  app/test-regex/main.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
app/test-regex/main.c index renamed from app/test-regex/main.c +0 -0

0d35f45..e6080b4 100644

app/test-regex/main.c +3 -1
@@ -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 }
  	};
 
Quoted 4 lines
Quoted 3 lines

argvopt = argv;
--
2.8.4

Quoted 2 lines

Thanks,
Ori

Best regards

Lukasz

--
Lukasz Wojciechowski
Principal Software Engineer

Samsung R&D Institute Poland
Samsung Electronics
Office +48 22 377 88 25
[email protected]

#4 lore raw

19/10/2020 10:39, Ophir Munk:

Quoted 2 lines

Adding Thomas Monjalon
Thomas - when merging can you please remove the line: Cc: [email protected] ?

No it should be kept because the bug is in a previous release.

#5 lore raw
In reply to Lukasz Wojciechowski
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

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.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
Fixes de06137cb295 ("app/regex: add RegEx test application")

Applied, thanks