summaryrefslogtreecommitdiff
path: root/proxy_request.c
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2022-08-03 12:48:13 -0700
committerdormando <dormando@rydia.net>2022-08-03 12:48:13 -0700
commitbdccfdbe653ba5d2cd028af5d848c73e9dbe1c2b (patch)
tree9df301b62f5c5a6fdcd933814f4f6fa993def91e /proxy_request.c
parent4f27245d04e6bd0e7b32b2f930fe78bbae1080df (diff)
downloadmemcached-bdccfdbe653ba5d2cd028af5d848c73e9dbe1c2b.tar.gz
proxy: fix subtle parser bug for some cmds1.6.16
in the request parser the new endcap token was always the end of the line, but it should be the start of the next token. For some use cases the scanning stops early, or if we have too many tokens it would make the final token look like the rest of the line.
Diffstat (limited to 'proxy_request.c')
-rw-r--r--proxy_request.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/proxy_request.c b/proxy_request.c
index 3face1f..497e57c 100644
--- a/proxy_request.c
+++ b/proxy_request.c
@@ -23,29 +23,41 @@ static int _process_tokenize(mcp_parser_t *pr, const size_t max) {
while (s != end) {
switch (state) {
case 0:
+ // scanning for first non-space to find a token.
if (*s != ' ') {
pr->tokens[curtoken] = s - pr->request;
if (++curtoken == max) {
- goto endloop;
+ s++;
+ state = 2;
+ break;
}
state = 1;
}
s++;
break;
case 1:
+ // advance over a token
if (*s != ' ') {
s++;
} else {
state = 0;
}
break;
+ case 2:
+ // hit max tokens before end of the line.
+ // keep advancing so we can place endcap token.
+ if (*s == ' ') {
+ goto endloop;
+ }
+ s++;
+ break;
}
}
endloop:
// endcap token so we can quickly find the length of any token by looking
// at the next one.
- pr->tokens[curtoken] = len;
+ pr->tokens[curtoken] = s - pr->request;
pr->ntokens = curtoken;
P_DEBUG("%s: cur_tokens: %d\n", __func__, curtoken);