Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request: trim headers values also when there is no name #424

Merged
merged 3 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion htp/htp_request_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,12 @@ htp_status_t htp_parse_request_header_generic(htp_connp_t *connp, htp_header_t *
h->name = bstr_dup_c("");
if (h->name == NULL) return HTP_ERROR;

h->value = bstr_dup_mem(data, len);
// Ignore LWS after field-content.
value_end = len - 1;
while ((value_end > 0) && (htp_is_lws(data[value_end]))) {
value_end--;
}
h->value = bstr_dup_mem(data, value_end + 1);
if (h->value == NULL) {
bstr_free(h->name);
return HTP_ERROR;
Expand Down
15 changes: 11 additions & 4 deletions test/fuzz/fuzz_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ static int txDiff(void* rstx, htp_tx_t * ctx) {
uint32_t rsnbh = htp_tx_request_headers_size(rstx);
if (rsnbh != nbhc) {
printf("Assertion failure: got nbheaders c=%d versus rust=%d\n", nbhc, rsnbh);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
Expand All @@ -349,14 +350,16 @@ static int txDiff(void* rstx, htp_tx_t * ctx) {
htp_header_t *h = (htp_header_t *) htp_table_get_index(ctx->request_headers, i, NULL);
void *rsh = htp_tx_request_header_index(rstx, (size_t) i);
if (bstrDiff(htp_header_name(rsh), h->name, "header-name")) {
printf("request header %d is different\n", i);
printf("request header name %d is different\n", i);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
return 1;
}
if (bstrDiff(htp_header_value(rsh), h->value, "header-value")) {
printf("request header %d is different\n", i);
printf("request header value %d is different\n", i);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
Expand All @@ -368,6 +371,7 @@ static int txDiff(void* rstx, htp_tx_t * ctx) {
rsnbh = htp_tx_response_headers_size(rstx);
if (rsnbh != nbhc) {
printf("Assertion failure: got nbheaders c=%d versus rust=%d\n", nbhc, rsnbh);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
Expand All @@ -378,14 +382,16 @@ static int txDiff(void* rstx, htp_tx_t * ctx) {
htp_header_t *h = (htp_header_t *) htp_table_get_index(ctx->response_headers, i, NULL);
void *rsh = htp_tx_response_header_index(rstx, (size_t) i);
if (bstrDiff(htp_header_name(rsh), h->name, "header-name")) {
printf("response header %d is different\n", i);
printf("response header name %d is different\n", i);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
return 1;
}
if (bstrDiff(htp_header_value(rsh), h->value, "header-value")) {
printf("response header %d is different\n", i);
printf("response header value %d is different\n", i);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
Expand All @@ -401,6 +407,7 @@ static int connDiff(void* rsconnp, htp_conn_t * conn) {
uint32_t c = htp_list_size(conn->transactions);
if (rs != c) {
printf("Assertion failure: got nbtx c=%d versus rust=%d\n", c, rs);
fflush(stdout);
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
abort();
#endif
Expand Down
Loading