Skip to content

Commit

Permalink
stricter validation of header names (follows h2o/h2o#974, validation …
Browse files Browse the repository at this point in the history
…rule matches that of Firefox (see `nsHttp::IsValidToken`).
  • Loading branch information
kazuho committed Aug 22, 2016
1 parent 4081861 commit 8efc8f1
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions picohttpparser.c
Expand Up @@ -93,7 +93,7 @@
} while (0)

static const char *token_char_map = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\1\1\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0"
"\0\1\0\1\1\1\1\1\0\0\1\1\0\1\1\0\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0"
"\0\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\1\1"
"\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\1\0\1\0"
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
Expand Down Expand Up @@ -279,23 +279,26 @@ static const char *parse_headers(const char *buf, const char *buf_end, struct ph
return NULL;
}
if (!(*num_headers != 0 && (*buf == ' ' || *buf == '\t'))) {
static const char ALIGNED(16) ranges1[] = "::\x00\037";
int found;
if (!token_char_map[(unsigned char)*buf]) {
*ret = -1;
return NULL;
}
/* parsing name, but do not discard SP before colon, see
* http://www.mozilla.org/security/announce/2006/mfsa2006-33.html */
headers[*num_headers].name = buf;
static const char ranges1[] __attribute__((aligned(16))) = "\x00 " /* control chars and up to SP */
"\"\"" /* 0x22 */
"()" /* 0x28,0x29 */
",," /* 0x2c */
"//" /* 0x2f */
":@" /* 0x3a-0x40 */
"[]" /* 0x5b-0x5d */
"{\377"; /* 0x7b-0xff */
int found;
buf = findchar_fast(buf, buf_end, ranges1, sizeof(ranges1) - 1, &found);
if (!found) {
CHECK_EOF();
}
while (1) {
if (*buf == ':') {
break;
} else if (*buf < ' ') {
} else if (!token_char_map[(unsigned char)*buf]) {
*ret = -1;
return NULL;
}
Expand Down

0 comments on commit 8efc8f1

Please sign in to comment.