diff mbox

lib: fwts_args: fix arg parameter sanity range checking

Message ID 20170120105420.3528-1-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Jan. 20, 2017, 10:54 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

An earlier commit remove the arg parameter sanity range checking
which should be re-instated. Add the code back.

Fixes: 973a296cad30 ("v2 - lib: fwts_args: handle cases to set optarg_handler for long options.")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_args.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Alex Hung Jan. 23, 2017, 7:20 a.m. UTC | #1
On 2017-01-20 06:54 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> An earlier commit remove the arg parameter sanity range checking
> which should be re-instated. Add the code back.
>
> Fixes: 973a296cad30 ("v2 - lib: fwts_args: handle cases to set optarg_handler for long options.")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_args.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index 5d47547..fec656f 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -212,6 +212,16 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>  		}
>  	}
>
> +	/* We've collected all the args, now sanity check the values */
> +
> +	fwts_list_foreach(item, &options_list) {
> +		options_table = fwts_list_data(fwts_options_table *, item);
> +		if (options_table->optarg_check != NULL) {
> +			ret = options_table->optarg_check(fw);
> +			if (ret != FWTS_OK)
> +				break;
> +		}
> +	}
>  exit:
>  	free(short_options);
>  	free(long_options);
>

Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Feb. 2, 2017, 1:23 a.m. UTC | #2
On 2017年01月20日 18:54, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> An earlier commit remove the arg parameter sanity range checking
> which should be re-instated. Add the code back.
>
> Fixes: 973a296cad30 ("v2 - lib: fwts_args: handle cases to set optarg_handler for long options.")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_args.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index 5d47547..fec656f 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -212,6 +212,16 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
>  		}
>  	}
>
> +	/* We've collected all the args, now sanity check the values */
> +
> +	fwts_list_foreach(item, &options_list) {
> +		options_table = fwts_list_data(fwts_options_table *, item);
> +		if (options_table->optarg_check != NULL) {
> +			ret = options_table->optarg_check(fw);
> +			if (ret != FWTS_OK)
> +				break;
> +		}
> +	}
>  exit:
>  	free(short_options);
>  	free(long_options);
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index 5d47547..fec656f 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -212,6 +212,16 @@  int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[])
 		}
 	}
 
+	/* We've collected all the args, now sanity check the values */
+
+	fwts_list_foreach(item, &options_list) {
+		options_table = fwts_list_data(fwts_options_table *, item);
+		if (options_table->optarg_check != NULL) {
+			ret = options_table->optarg_check(fw);
+			if (ret != FWTS_OK)
+				break;
+		}
+	}
 exit:
 	free(short_options);
 	free(long_options);