From 04f99a84d56d7ac3f9633d72844fed24a854f0fb Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 28 Jul 2025 22:17:19 +0100 Subject: [PATCH] cmd: fix b_arglist_get_* functions not checking index parameter --- cmd/arglist.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmd/arglist.c b/cmd/arglist.c index 6fc9e58..9314c92 100644 --- a/cmd/arglist.c +++ b/cmd/arglist.c @@ -698,6 +698,12 @@ b_status b_arglist_get_string( b_arglist_iterator it = {0}; b_arglist_iterator_begin(args, opt_id, arg_id, &it); while (b_arglist_iterator_is_valid(&it)) { + if (index > 0) { + index--; + b_arglist_iterator_next(&it); + continue; + } + if (it.value && it.value->val_str) { *out = it.value->val_str; return B_SUCCESS; @@ -716,6 +722,12 @@ b_status b_arglist_get_int( b_arglist_iterator it = {0}; b_arglist_iterator_begin(args, opt_id, arg_id, &it); while (b_arglist_iterator_is_valid(&it)) { + if (index > 0) { + index--; + b_arglist_iterator_next(&it); + continue; + } + if (it.value) { *out = it.value->val_int; return B_SUCCESS; @@ -734,6 +746,12 @@ b_status b_arglist_get_uint( b_arglist_iterator it = {0}; b_arglist_iterator_begin(args, opt_id, arg_id, &it); while (b_arglist_iterator_is_valid(&it)) { + if (index > 0) { + index--; + b_arglist_iterator_next(&it); + continue; + } + if (it.value && it.value->val_uint) { *out = it.value->val_uint; return B_SUCCESS;