diff options
author | Sailesh Mukil <sailesh@apache.org> | 2022-07-25 16:18:20 -0700 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2022-07-25 20:13:15 -0700 |
commit | 4f07a597bbd0367d6458ed4c65f47ec9ca3910cd (patch) | |
tree | ba40ff349d3ae9a80b8e13a615bb8f46e368d9ab /proxy_request.c | |
parent | 6aa0d9b9a7040e51e556398803096576c21f5c9a (diff) | |
download | memcached-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.
Diffstat (limited to 'proxy_request.c')
-rw-r--r-- | proxy_request.c | 11 |
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. |