Commit 7f8c4640 authored by ale's avatar ale

alternate implementation of get_cookie that does not leak memory forever

parent 4f9671df
......@@ -254,25 +254,28 @@ static int is_valid_redir(request_rec *r,
* @return the cookie value, or an empty string if no cookie was found.
*/
static char *get_cookie(request_rec *r, const char *cookie_name) {
char *cookie_value = NULL, *strptr = NULL, *token;
const char *cookies_c = apr_table_get(r->headers_in, "Cookie");
char *rv = NULL, *cookie, *tokenizerCtx = NULL;
int cookie_name_len;
// How do we know this is writable? TODO: make a copy.
char *cookies_c = (char *)apr_table_get(r->headers_in, "Cookie");
if (cookies_c == NULL) {
return cookie_value;
return NULL;
}
while ((token = strtok_r(apr_pstrdup(r->pool, cookies_c), ";", &strptr)) != NULL) {
char *sep = strchr(token, '=');
if (!sep) {
continue;
}
*sep++ = '\0';
if (!strcmp(token, cookie_name)) {
cookie_value = sep;
cookie_name_len = strlen(cookie_name);
cookie = apr_strtok(cookies_c, ";", &tokenizerCtx);
do {
while (cookie != NULL && *cookie == ' ')
cookie++;
if (strncmp(cookie, cookie_name, cookie_name_len) == 0) {
cookie += (cookie_name_len + 1);
rv = apr_pstrdup(r->pool, cookie);
break;
}
}
return cookie_value;
cookie = apr_strtok(NULL, ";", &tokenizerCtx);
} while (cookie != NULL);
return rv;
}
char *get_cookie_name(request_rec *r) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment