From a50bbcb6566f76da3da32c18afd66cb674bbbc83 Mon Sep 17 00:00:00 2001 From: YaacovHazan <31382944+YaacovHazan@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:48:36 +0200 Subject: [PATCH] redis-cli fixes around help hints version filtering (#13097) - In removeUnsupportedArgs, trying to access the next item after the last one and causing an out of bounds read. - In versionIsSupported, when the 'version' is equal to 'since', the return value is 0 (not supported). Also, change the function to return `not supported` in case they have different numbers of digits Both issues were found by `Non-interactive non-TTY CLI: Test command-line hinting - old server` under `test-sanitizer-address` (When changing the `src/version.h` locally to `8.0.0`) The new `MAXAGE` argument inside `client-kill` triggered the issue (new argument at the end of the list) --------- Co-authored-by: YaacovHazan --- src/redis-cli.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/redis-cli.c b/src/redis-cli.c index 10b94bdc8..b8e7d9a8e 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -745,8 +745,13 @@ static int versionIsSupported(sds version, sds since) { } versionPos = strchr(versionPos, '.'); sincePos = strchr(sincePos, '.'); - if (!versionPos || !sincePos) - return 0; + + /* If we finished to parse both `version` and `since`, it means they are equal */ + if (!versionPos && !sincePos) return 1; + + /* Different number of digits considered as not supported */ + if (!versionPos || !sincePos) return 0; + versionPos++; sincePos++; } @@ -763,7 +768,7 @@ static void removeUnsupportedArgs(struct cliCommandArg *args, int *numargs, sds i++; continue; } - for (j = i; j != *numargs; j++) { + for (j = i; j != *numargs - 1; j++) { args[j] = args[j + 1]; } (*numargs)--;