Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
http: fix Accept-Encoding parsing
  • Loading branch information
stbenz authored and perexg committed May 22, 2015
1 parent 8e4a989 commit ef5b43a
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/http.c
@@ -1,6 +1,6 @@
/*
* tvheadend, HTTP interface
* Copyright (C) 2007 Andreas Öman
* Copyright (C) 2007 Andreas Öman
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -319,24 +319,30 @@ int
http_encoding_valid(http_connection_t *hc, const char *encoding)
{
const char *accept;
size_t l = strlen(encoding);
size_t i;
char *tokbuf, *tok, *saveptr, *q, *s;

accept = http_arg_get(&hc->hc_args, "accept-encoding");
if (!accept)
return 0;

while (*accept) {
for (i = 0; i < l; i++)
if (tolower(accept[i]) != encoding[i])
break;
if (i < l)
continue;
accept += l;
while (*accept == ' ')
accept++;
if (*accept == ',' || *accept == '\0')
tokbuf = tvh_strdupa(accept);
tok = strtok_r(tokbuf, ",", &saveptr);
while (tok) {
while (*tok == ' ')

This comment has been minimized.

Copy link
@barberio

barberio May 23, 2015

Compile time error:
src/http.c: In function ‘http_encoding_valid’:
src/http.c:331:17: error: ‘saveptr’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
while (*tok == ' ')
^
cc1: all warnings being treated as errors

tok++;
// check for semicolon
if ((q = strchr(tok, ';')) != NULL) {
*q = '\0';
q++;
while (*q == ' ')
q++;
}
if ((s = strchr(tok, ' ')) != NULL)
*s = '\0';
// check for matching encoding with q > 0
if ((!strcasecmp(tok, encoding) || !strcmp(tok, "*")) && (q == NULL || strncmp(q, "q=0.000", strlen(q))))
return 1;
tok = strtok_r(NULL, ",", &saveptr);
}
return 0;
}
Expand Down

0 comments on commit ef5b43a

Please sign in to comment.