From: Jaroslav Kysela Date: Thu, 8 Feb 2018 17:13:19 +0000 (+0100) Subject: http: fix http_get_header_value() - digest auth X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ad8a81d8ca0b8ae51beb2c6bb2b327310811160;p=thirdparty%2Ftvheadend.git http: fix http_get_header_value() - digest auth --- diff --git a/src/http.c b/src/http.c index 46635a1b2..59d91e24c 100644 --- a/src/http.c +++ b/src/http.c @@ -561,31 +561,33 @@ http_header_match(http_connection_t *hc, const char *name, const char *value) 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; }