mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-27 12:26:24 +00:00
Implement mg_http_parse_header2()
Which is a replacement of (deprecated) `mg_http_parse_header`, but, similarly to `asprintf`, allocates a new buffer if the client-provided one is not large enough. Also use it throughout mongoose code, and thus some header-related limitations are removed; in particular, https://github.com/cesanta/mongoose/issues/813 is fixed. CL: Mongoose Web Server: Deprecate `mg_http_parse_header()` and implement `mg_http_parse_header2()` instead, which allocates a new buffer if the client-provided one is not large enough (similarly to `asprintf`). CL: Mongoose Web Server: Fix limitations of header value lengths, e.g. when parsing authentication headers such as nonce, etc. PUBLISHED_FROM=c75b1bbbbdb294ea85075ce69b1368f115fdd1ef
This commit is contained in:
1 parent
a8a7d2cf7e
commit
b9b20c6494
10 files changed
+541
-109
No files matched your search
@@ -4941,12 +4941,34 @@ static const char *test_http_parse_header(void) {
|
||||
"xx=1 kl yy, ert=234 kl=123, "
|
||||
"uri=\"/?naii=x,y\";ii=\"12\\\"34\" zz='aa bb',tt=2,gf=\"xx d=1234");
|
||||
char buf[20];
|
||||
char *buf2;
|
||||
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "ert", buf, sizeof(buf)), 3);
|
||||
ASSERT_STREQ(buf, "234");
|
||||
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "ert", buf, 2), 0);
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "ert", buf, 3), 0);
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "ert", buf, 4), 3);
|
||||
|
||||
buf2 = buf;
|
||||
ASSERT_EQ(mg_http_parse_header2(&h, "ert", &buf2, 2), 3);
|
||||
ASSERT(buf2 != buf);
|
||||
free(buf2);
|
||||
|
||||
buf2 = buf;
|
||||
ASSERT_EQ(mg_http_parse_header2(&h, "ert", &buf2, 3), 3);
|
||||
ASSERT(buf2 != buf);
|
||||
free(buf2);
|
||||
|
||||
buf2 = buf;
|
||||
ASSERT_EQ(mg_http_parse_header2(&h, "ert", &buf2, 4), 3);
|
||||
ASSERT(buf2 == buf);
|
||||
|
||||
buf2 = NULL;
|
||||
ASSERT_EQ(mg_http_parse_header2(&h, "ert", &buf2, 0), 3);
|
||||
ASSERT_STREQ(buf2, "234");
|
||||
free(buf2);
|
||||
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "gf", buf, sizeof(buf)), 0);
|
||||
ASSERT_EQ(mg_http_parse_header(&h, "zz", buf, sizeof(buf)), 5);
|
||||
ASSERT_STREQ(buf, "aa bb");
|
||||
|
||||
Reference in new issue
Block a user