From: Jaroslav Kysela Date: Thu, 8 Feb 2018 17:13:19 +0000 (+0100) Subject: http: fix http_get_header_value() - digest auth X-Git-Tag: v4.2.6~33 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3bc3712c6d79d072654568749ff77c3239cea7b6;p=thirdparty%2Ftvheadend.git http: fix http_get_header_value() - digest auth --- diff --git a/src/http.c b/src/http.c index 1573e4e2a..96053ee16 100644 --- a/src/http.c +++ b/src/http.c @@ -476,31 +476,33 @@ http_encoding_valid(http_connection_t *hc, const char *encoding) static char * http_get_header_value(const char *hdr, const char *name) { - char *tokbuf, *tok, *saveptr = NULL, *q, *s; - - tokbuf = tvh_strdupa(hdr); - tok = strtok_r(tokbuf, ",", &saveptr); - while (tok) { - while (*tok == ' ') - tok++; - if ((q = strchr(tok, '=')) == NULL) - goto next; - *q = '\0'; - if (strcasecmp(tok, name)) - goto next; - s = q + 1; + char *s, *start, *val; + s = tvh_strdupa(hdr); + while (*s) { + while (*s && *s <= ' ') s++; + start = s; + while (*s && *s != '=') s++; + if (*s == '=') { + *s = '\0'; + s++; + } + while (*s && *s <= ' ') s++; if (*s == '"') { - q = strchr(++s, '"'); - if (q) - *q = '\0'; + val = ++s; + while (*s && *s != '"') s++; + if (*s == '"') { + *s = '\0'; + s++; + } + while (*s && (*s <= ' ' || *s == ',')) s++; } else { - q = strchr(s, ' '); - if (q) - *q = '\0'; + val = s; + while (*s && *s != ',') s++; + *s = '\0'; + s++; } - return strdup(s); -next: - tok = strtok_r(NULL, ",", &saveptr); + if (*start && strcmp(name, start) == 0) + return strdup(val); } return NULL; }