From: Mathieu Desnoyers Date: Mon, 24 Jul 2017 21:15:53 +0000 (-0400) Subject: Fix: negative loop bound check X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=0ca8409d46a794bafa1cbd50eb531fc650d148c1;p=deliverable%2Fbabeltrace.git Fix: negative loop bound check Found by Coverity: CID 1376197 (#1 of 1): Negative loop bound (NEGATIVE_RETURNS) 3. negative_returns: Using unsigned variable bt_value_array_size(run_args) in a loop exit condition. Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index 4fba2b162..2978ab48a 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -2719,7 +2719,7 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, { struct bt_config *cfg = NULL; const char **argv; - size_t i; + int64_t i, len; const size_t argc = bt_value_array_size(run_args) + 1; argv = calloc(argc, sizeof(*argv)); @@ -2730,7 +2730,12 @@ struct bt_config *bt_config_run_from_args_array(struct bt_value *run_args, argv[0] = "run"; - for (i = 0; i < bt_value_array_size(run_args); i++) { + len = bt_value_array_size(run_args); + if (len < 0) { + printf_err("Invalid executable arguments\n"); + goto end; + } + for (i = 0; i < len; i++) { int ret; struct bt_value *arg_value = bt_value_array_get(run_args, i); const char *arg;