From 82cc37d0f5fcfc5aae8ba631a4054a4701e4a557 Mon Sep 17 00:00:00 2001 From: Pierre Ayoub Date: Thu, 20 Feb 2025 08:41:42 +0100 Subject: [PATCH] fix(git-bulk): fix a bad integer expression (#1198) Fix a logic error inside the `allowedargcount()` function. This function may be called with one or two arguments. However, no default values are assigned to `$1` and `$2` that are used inside a numerical comparison. Therefore, when using a bad number of arguments for the following lines: ``` listall|purge) allowedargcount 1;; addcurrent|removeworkspace) allowedargcount 2;; ``` Then, we would get the error `[: : integer expression expected`. To fix this, we assign the 0 default value to `$1` and `$2`, such that we trigger the error message destined to the user without any integer error when there is a bad number of argument and that the function is called with only 1 argument instead of 2. --- bin/git-bulk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/git-bulk b/bin/git-bulk index e3bdd66..48c1954 100755 --- a/bin/git-bulk +++ b/bin/git-bulk @@ -129,7 +129,7 @@ function wsnameToCurrent () { # helper to check number of arguments. function allowedargcount () { - if [ "$paramcount" -ne "$1" ] && [ "$paramcount" -ne "$2" ]; then + if [ "$paramcount" -ne "${1:-0}" ] && [ "$paramcount" -ne "${2:-0}" ]; then echo 1>&2 "error: wrong number of arguments" && usage; exit 1; fi