Skip to contentSkip to conversation

init: option parsing fixes

PATCH Applied Stefan Hajnoczi 2 participants 4 messages Feb 4, 2014 – Feb 5, 2014

lore
Share & tools
lore
#0 lore raw

cover init: option parsing fixes

Patch 1 changes --minimal from optional_argument to no_argument. There seems to be no reason why optional_argument was used (the option doesn't use optarg).

Patch 2 fixes a segfault when --output-format is used without an argument.

Stefan Hajnoczi (2):
init: --minimal does not take an optional argument
init: log error on missing --output-format argument

 init.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 1 line
1.8.5.3
#1 lore raw

PATCH 1/2 init: --minimal does not take an optional argument

---
 init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
init.c +1 -1
index cc35e2b..05c73ef 100644
@@ -100,7 +100,7 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
 	},
 	{
 		.name		= (char *) "minimal",
-		.has_arg	= optional_argument,
+		.has_arg	= no_argument,
 		.val		= 'm' | FIO_CLIENT_FLAG,
 	},
 	{
Signature · 1 line
1.8.5.3
#2 lore raw

PATCH 2/2 init: log error on missing --output-format argument

In reply to Stefan Hajnoczi

strcmp(optarg, "foo") will crash if --output-format was given without an argument. Log an error and exit properly instead of crashing.

---
 init.c | 6 ++++++
 1 file changed, 6 insertions(+)
init.c +6 -0
index 05c73ef..6c48d3a 100644
@@ -1652,6 +1652,12 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
 			output_format = FIO_OUTPUT_TERSE;
 			break;
 		case 'F':
+			if (!optarg) {
+				log_err("fio: missing --output-format argument\n");
+				exit_val = 1;
+				do_exit++;
+				break;
+			}
 			if (!strcmp(optarg, "minimal") ||
 			    !strcmp(optarg, "terse") ||
 			    !strcmp(optarg, "csv"))
Signature · 1 line
1.8.5.3
Applied
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 11 lines · Stefan Hajnoczi

Patch 1 changes --minimal from optional_argument to no_argument. There seems to be no reason why optional_argument was used (the option doesn't use optarg).

Patch 2 fixes a segfault when --output-format is used without an argument.

Stefan Hajnoczi (2):
init: --minimal does not take an optional argument
init: log error on missing --output-format argument

 init.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Thanks, applied both!

Signature · 1 line
Jens Axboe