Skip to content

Commit

Permalink
CLEANUP: Fix rest_ntokens calculation on bop mget/smget
Browse files Browse the repository at this point in the history
  • Loading branch information
namsic committed Dec 15, 2023
1 parent 615af38 commit a1f856f
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -12615,27 +12620,14 @@ static void process_bop_command(conn *c, token_t *tokens, const size_t ntokens)
c->coll_efilter.ncompval = 0;
}

if (rest_ntokens > 1) {
if ((rest_ntokens < 1) || (rest_ntokens > 2) ||
(rest_ntokens > 1 && !safe_strtoul(tokens[read_ntokens++].value, &offset)) ||
(rest_ntokens > 0 && !safe_strtoul(tokens[read_ntokens++].value, &count))) {
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)) {
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))) {
print_invalid_command(c, tokens, ntokens);
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
}

/* validation checking on arguments */
if (numkeys > ((lenkeys/2) + 1) ||
lenkeys > ((numkeys*KEY_MAX_LENGTH) + numkeys-1) ||
Expand Down

0 comments on commit a1f856f

Please sign in to comment.