summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSailesh Mukil <sailesh@apache.org>2022-07-25 16:18:20 -0700
committerdormando <dormando@rydia.net>2022-07-25 20:13:15 -0700
commit4f07a597bbd0367d6458ed4c65f47ec9ca3910cd (patch)
treeba40ff349d3ae9a80b8e13a615bb8f46e368d9ab
parent6aa0d9b9a7040e51e556398803096576c21f5c9a (diff)
downloadmemcached-4f07a597bbd0367d6458ed4c65f47ec9ca3910cd.tar.gz
proxy: mcplib_request_token() doesn't delimit the final token in a request
mcplib_request_token() allows us to parse each token in a request string. The existing implementation delimits tokens using <whitespace>. This approach works for every token but the last one which will be followed by \r\n. This patch uses the token offsets present within the request parser to calculate the token boundaries instead of looping until the next delimiter.
-rw-r--r--proxy_request.c11
1 files changed, 4 insertions, 7 deletions
diff --git a/proxy_request.c b/proxy_request.c
index f351cc1..259ec90 100644
--- a/proxy_request.c
+++ b/proxy_request.c
@@ -653,15 +653,12 @@ int mcplib_request_token(lua_State *L) {
lua_pop(L, 1); // got a nil, drop it.
// token not uploaded yet. find the len.
- char *s = (char *) &rq->pr.request[rq->pr.tokens[token-1]];
- char *e = s;
- while (*e != ' ') {
- e++;
- }
- vlen = e - s;
+ char *start = (char *) &rq->pr.request[rq->pr.tokens[token-1]];
+ char *end = (char *) &rq->pr.request[rq->pr.tokens[token]];
+ vlen = end - start;
P_DEBUG("%s: pushing token of len: %lu\n", __func__, vlen);
- lua_pushlstring(L, s, vlen);
+ lua_pushlstring(L, start, vlen);
lua_pushvalue(L, -1); // copy
lua_rawseti(L, -3, token); // pops copy.