mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +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
+3
-1
@@ -45,7 +45,9 @@ COMMON_FEATURE_FLAGS = \
|
||||
-DMG_ENABLE_SNTP -DMG_SNTP_NO_DELAY_CORRECTION \
|
||||
-DMG_ENABLE_HTTP_STREAMING_MULTIPART
|
||||
UNIX_FEATURE_FLAGS=-DMG_ENABLE_IPV6 -DMG_ENABLE_SSL
|
||||
CFLAGS = -W -Wall -Wundef -Werror -g -O0 -Wno-multichar -D__USE_MISC \
|
||||
# TODO: remove -Wno-deprecated-declarations once deprecated
|
||||
# `mg_http_parse_header()` is removed from mongoose.
|
||||
CFLAGS = -W -Wall -Wundef -Werror -Wno-deprecated-declarations -g -O0 -Wno-multichar -D__USE_MISC \
|
||||
$(COMMON_FEATURE_FLAGS) $(UNIX_FEATURE_FLAGS) \
|
||||
$(patsubst %,-I%,$(subst :, ,$(VPATH))) \
|
||||
-include unit_test.h -pthread $(CFLAGS_EXTRA)
|
||||
|
||||
@@ -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