From 04f0cd5623ce9367f5b5e3f7ba909b7d9ac4cda6 Mon Sep 17 00:00:00 2001 From: Namjae Kim Date: Thu, 14 Dec 2023 16:22:24 +0900 Subject: [PATCH] CLEANUP: Fix rest_ntokens calculation on bop mget/smget --- memcached.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/memcached.c b/memcached.c index 7740562a1..f8d2480ed 100644 --- a/memcached.c +++ b/memcached.c @@ -12594,14 +12594,19 @@ static void process_bop_command(conn *c, token_t *tokens, const size_t ntokens) } int read_ntokens = BOP_KEY_TOKEN + 3; + int post_ntokens = 1; /* "\r\n" */ #ifdef JHPARK_OLD_SMGET_INTERFACE - int post_ntokens = (smgmode > 0 ? 3 : 2); /* "\r\n" */ + if (smgmode > 0) { + post_ntokens += 1; + } #else - int post_ntokens = (unique ? 3 : 2); /* "\r\n" */ + if (unique) { + post_ntokens += 1; + } #endif int rest_ntokens = ntokens - read_ntokens - post_ntokens; - if (rest_ntokens >= 3) { + if (rest_ntokens > 3) { int used_ntokens = get_efilter_from_tokens(&tokens[read_ntokens], rest_ntokens, &c->coll_efilter); if (used_ntokens == -1) { @@ -12616,24 +12621,24 @@ static void process_bop_command(conn *c, token_t *tokens, const size_t ntokens) } if (rest_ntokens > 1) { - print_invalid_command(c, tokens, ntokens); - out_string(c, "CLIENT_ERROR bad command line format"); - return; - } - - if (rest_ntokens == 0) { - if (! safe_strtoul(tokens[read_ntokens].value, &count)) { + if (! safe_strtoul(tokens[read_ntokens++].value, &offset)) { print_invalid_command(c, tokens, ntokens); out_string(c, "CLIENT_ERROR bad command line format"); return; } - } else { /* rest_ntokens == 1 */ - if ((! safe_strtoul(tokens[read_ntokens].value, &offset)) || - (! safe_strtoul(tokens[read_ntokens+1].value, &count))) { + rest_ntokens -= 1; + } + + if (rest_ntokens == 1) { + if (! safe_strtoul(tokens[read_ntokens++].value, &count)) { print_invalid_command(c, tokens, ntokens); out_string(c, "CLIENT_ERROR bad command line format"); return; } + } else { + print_invalid_command(c, tokens, ntokens); + out_string(c, "CLIENT_ERROR bad command line format"); + return; } /* validation checking on arguments */