summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuwentan <[email protected]>2024-01-08 12:08:16 +0800
committerliuwentan <[email protected]>2024-01-08 12:08:16 +0800
commit9f81cecf1f2e1ea26191784709b5f3ab6d3804de (patch)
tree523f6ec9a79ef218c6601c94721b6c93dfe31b8a
parentd60a54627d116fbba171c371b86a2b8e3a1acc5d (diff)
[HTTP_DECODER]bugfix for half_decoder's invalid pointer
-rw-r--r--src/http_decoder/http_decoder.c11
-rw-r--r--src/http_decoder/http_decoder_half.c7
-rw-r--r--test/http_decoder/CMakeLists.txt11
-rw-r--r--test/http_decoder/http_decoder_gtest.cpp4
-rw-r--r--test/http_decoder/http_pcap/http_multi_parse_error.pcap (renamed from test/http_decoder/http_pcap/http_post_no_host.pcap)bin123982 -> 123982 bytes
-rw-r--r--test/http_decoder/http_pcap/http_upgrade_websocket.pcapbin0 -> 8519 bytes
-rw-r--r--test/http_decoder/test_result_json/http_multi_parse_error.json114
-rw-r--r--test/http_decoder/test_result_json/http_post_no_host.json1
-rw-r--r--test/http_decoder/test_result_json/http_upgrade_websocket.json37
9 files changed, 167 insertions, 18 deletions
diff --git a/src/http_decoder/http_decoder.c b/src/http_decoder/http_decoder.c
index 3d39eba..3e4e973 100644
--- a/src/http_decoder/http_decoder.c
+++ b/src/http_decoder/http_decoder.c
@@ -370,6 +370,7 @@ int http_decoder_entry(struct session *sess, int events,
}
const char *payload = session_get0_current_payload(sess, &payload_len);
+ // printf("session:%s\n", session_get0_readable_addr(sess));
if (events & SESS_EV_OPENING) {
if (queue != NULL) {
@@ -423,15 +424,7 @@ int http_decoder_entry(struct session *sess, int events,
ctx->http_ev_ctx->ref_queue = queue;
ctx->http_ev_ctx->ref_session = sess;
- ret = http_decoder_half_parse(cur_half, ctx->http_ev_ctx, payload,
- payload_len);
- if (ret < 0) {
- if (dir == PACKET_DIRECTION_C2S) {
- http_decoder_result_queue_pop(queue, queue->req_index);
- } else {
- http_decoder_result_queue_pop(queue, queue->res_index);
- }
- }
+ http_decoder_half_parse(cur_half, ctx->http_ev_ctx, payload, payload_len);
return 0;
}
diff --git a/src/http_decoder/http_decoder_half.c b/src/http_decoder/http_decoder_half.c
index 9e24a8b..7030036 100644
--- a/src/http_decoder/http_decoder_half.c
+++ b/src/http_decoder/http_decoder_half.c
@@ -104,6 +104,8 @@ on_message_begin(llhttp_t *http)
assert(half);
half->event = HTTP_EVENT_INIT;
+ half->ref_data = NULL;
+
return 0;
}
@@ -732,9 +734,8 @@ http_decoder_half_parse(struct http_decoder_half *half, void *http_ev_ctx,
if (ret < 0) {
fprintf(stderr,
- "llhttp_execute parse error: %s in position:%s err_reason:%s\n",
- llhttp_errno_name(half->error), llhttp_get_error_pos(&half->parser),
- half->parser.reason);
+ "llhttp_execute parse error: %s err_reason:%s\n",
+ llhttp_errno_name(half->error), half->parser.reason);
return -1;
}
diff --git a/test/http_decoder/CMakeLists.txt b/test/http_decoder/CMakeLists.txt
index 0ac3a23..abca12d 100644
--- a/test/http_decoder/CMakeLists.txt
+++ b/test/http_decoder/CMakeLists.txt
@@ -91,12 +91,15 @@ add_test(NAME HTTP_CONNECT_FLOOD_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURC
add_test(NAME HTTP_GET_MALFORMED_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_result_json/http_get_malformed.json
-f "find ${CMAKE_CURRENT_SOURCE_DIR}/http_pcap/ -name http_get_malformed.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
-# add_test(NAME HTTP_POST_NO_HOST_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_result_json/http_post_no_host.json
-# -f "find ${CMAKE_CURRENT_SOURCE_DIR}/http_pcap/ -name http_post_no_host.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
-
add_test(NAME HTTP_HEADER_VALUE_EMPTY_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_result_json/http_header_value_empty.json
-f "find ${CMAKE_CURRENT_SOURCE_DIR}/http_pcap/ -name http_header_value_empty.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
+add_test(NAME HTTP_UPGRADE_WEBSOCKET_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_result_json/http_upgrade_websocket.json
+ -f "find ${CMAKE_CURRENT_SOURCE_DIR}/http_pcap/ -name http_upgrade_websocket.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
+
+add_test(NAME HTTP_MULTI_PARSE_ERROR_TEST COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/test_result_json/http_multi_parse_error.json
+ -f "find ${CMAKE_CURRENT_SOURCE_DIR}/http_pcap/ -name http_multi_parse_error.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
+
set_tests_properties(HTTP_GET_SINGLE_TRANS_TEST
HTTP_GET_MULTI_TRANS_TEST
HTTP_GET_REQ_PIPELINE_TEST
@@ -117,4 +120,6 @@ set_tests_properties(HTTP_GET_SINGLE_TRANS_TEST
HTTP_CONNECT_FLOOD_TEST
HTTP_GET_MALFORMED_TEST
HTTP_HEADER_VALUE_EMPTY_TEST
+ HTTP_MULTI_PARSE_ERROR_TEST
+ HTTP_UPGRADE_WEBSOCKET_TEST
PROPERTIES FIXTURES_REQUIRED TestFixture) \ No newline at end of file
diff --git a/test/http_decoder/http_decoder_gtest.cpp b/test/http_decoder/http_decoder_gtest.cpp
index 832c541..95ac3a4 100644
--- a/test/http_decoder/http_decoder_gtest.cpp
+++ b/test/http_decoder/http_decoder_gtest.cpp
@@ -228,7 +228,7 @@ next:
if (msg_type == HTTP_MESSAGE_REQ_HEADER) {
sprintf(result_name, "HTTP_DECODER_RESULT_%d", g_result_count);
commit_test_result_json(ctx, result_name);
- //printf("req json:%s\n", cJSON_Print(ctx));
+ // printf("req json:%s\n", cJSON_Print(ctx));
session_set_ex_data(sess, exdata_idx, NULL);
g_result_count++;
}
@@ -236,7 +236,7 @@ next:
if (msg_type == HTTP_MESSAGE_RES_HEADER) {
sprintf(result_name, "HTTP_DECODER_RESULT_%d", g_result_count);
commit_test_result_json(ctx, result_name);
- //printf("res json:%s\n", cJSON_Print(ctx));
+ // printf("res json:%s\n", cJSON_Print(ctx));
session_set_ex_data(sess, exdata_idx, NULL);
g_result_count++;
}
diff --git a/test/http_decoder/http_pcap/http_post_no_host.pcap b/test/http_decoder/http_pcap/http_multi_parse_error.pcap
index 0dca059..0dca059 100644
--- a/test/http_decoder/http_pcap/http_post_no_host.pcap
+++ b/test/http_decoder/http_pcap/http_multi_parse_error.pcap
Binary files differ
diff --git a/test/http_decoder/http_pcap/http_upgrade_websocket.pcap b/test/http_decoder/http_pcap/http_upgrade_websocket.pcap
new file mode 100644
index 0000000..e1ac4d0
--- /dev/null
+++ b/test/http_decoder/http_pcap/http_upgrade_websocket.pcap
Binary files differ
diff --git a/test/http_decoder/test_result_json/http_multi_parse_error.json b/test/http_decoder/test_result_json/http_multi_parse_error.json
new file mode 100644
index 0000000..9a6f450
--- /dev/null
+++ b/test/http_decoder/test_result_json/http_multi_parse_error.json
@@ -0,0 +1,114 @@
+[
+ {
+ "Tuple4": "192.168.131.33.47164>192.168.204.67.4445",
+ "method": "POST",
+ "uri": "http://:4445/RPC2",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "User-Agent": "ulxmlrpcpp/1.7.5",
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Date": "Sat Sep 7 10:04:57 2019",
+ "Content-Length": "468",
+ "name": "HTTP_DECODER_RESULT_1"
+ },
+ {
+ "Tuple4": "192.168.131.33.47164>192.168.204.67.4445",
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Transfer-Encoding": "chunked",
+ "X-Powered-By": "ulxmlrpcpp/1.7.4",
+ "Date": "Sat Sep 7 01:09:08 2019",
+ "name": "HTTP_DECODER_RESULT_2"
+ },
+ {
+ "Tuple4": "192.168.131.33.47172>192.168.204.67.4445",
+ "method": "POST",
+ "uri": "http://:4445/RPC2",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "User-Agent": "ulxmlrpcpp/1.7.5",
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Date": "Sat Sep 7 10:05:13 2019",
+ "Content-Length": "468",
+ "name": "HTTP_DECODER_RESULT_3"
+ },
+ {
+ "Tuple4": "192.168.131.33.47172>192.168.204.67.4445",
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Transfer-Encoding": "chunked",
+ "X-Powered-By": "ulxmlrpcpp/1.7.4",
+ "Date": "Sat Sep 7 01:09:24 2019",
+ "name": "HTTP_DECODER_RESULT_4"
+ },
+ {
+ "Tuple4": "192.168.131.33.47196>192.168.204.67.4445",
+ "method": "POST",
+ "uri": "http://:4445/RPC2",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "User-Agent": "ulxmlrpcpp/1.7.5",
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Date": "Sat Sep 7 10:05:30 2019",
+ "Content-Length": "225",
+ "name": "HTTP_DECODER_RESULT_5"
+ },
+ {
+ "Tuple4": "192.168.131.33.47196>192.168.204.67.4445",
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Transfer-Encoding": "chunked",
+ "X-Powered-By": "ulxmlrpcpp/1.7.4",
+ "Date": "Sat Sep 7 01:09:42 2019",
+ "name": "HTTP_DECODER_RESULT_6"
+ },
+ {
+ "Tuple4": "192.168.131.33.47214>192.168.204.67.4445",
+ "method": "POST",
+ "uri": "http://:4445/RPC2",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "User-Agent": "ulxmlrpcpp/1.7.5",
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Date": "Sat Sep 7 10:05:47 2019",
+ "Content-Length": "461",
+ "name": "HTTP_DECODER_RESULT_7"
+ },
+ {
+ "Tuple4": "192.168.131.33.47214>192.168.204.67.4445",
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Connection": "Close",
+ "Content-Type": "text/xml",
+ "Transfer-Encoding": "chunked",
+ "X-Powered-By": "ulxmlrpcpp/1.7.4",
+ "Date": "Sat Sep 7 01:09:58 2019",
+ "name": "HTTP_DECODER_RESULT_8"
+ }
+] \ No newline at end of file
diff --git a/test/http_decoder/test_result_json/http_post_no_host.json b/test/http_decoder/test_result_json/http_post_no_host.json
deleted file mode 100644
index 0637a08..0000000
--- a/test/http_decoder/test_result_json/http_post_no_host.json
+++ /dev/null
@@ -1 +0,0 @@
-[] \ No newline at end of file
diff --git a/test/http_decoder/test_result_json/http_upgrade_websocket.json b/test/http_decoder/test_result_json/http_upgrade_websocket.json
new file mode 100644
index 0000000..7921ff3
--- /dev/null
+++ b/test/http_decoder/test_result_json/http_upgrade_websocket.json
@@ -0,0 +1,37 @@
+[
+ {
+ "Tuple4": "131.179.196.220.59631>131.179.196.46.9696",
+ "method": "GET",
+ "uri": "/",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "Host": "spurs.cs.ucla.edu:9696",
+ "Connection": "Upgrade",
+ "Pragma": "no-cache",
+ "Cache-Control": "no-cache",
+ "Upgrade": "websocket",
+ "Origin": "null",
+ "Sec-WebSocket-Version": "13",
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.124 Safari/537.36",
+ "Accept-Encoding": "gzip, deflate, sdch",
+ "Accept-Language": "en-US,en;q=0.8,lv;q=0.6,ru;q=0.4",
+ "Cookie": "s_cc=true; s_sq=%5B%5BB%5D%5D; iwe_user_noticecount_urn%3amace%3aucla.edu%3appid%3aperson%3a1223EF7211FC4EC1965579D0B8D85FBA=2; __utma=125574670.1759122974.1407127284.1407127284.1415755402.2; __utmc=125574670; __utma=126236063.2139843507.1390525421.1433785187.1435706244.46; __utmc=126236063; __utmz=126236063.1427934389.33.5.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _ucla_sso=2015-07-02T11%3A34%3A30-07%3A00; _ga=GA1.2.1759122974.1407127284",
+ "Sec-WebSocket-Key": "sgD1adxQ3mk6BbBqab7owA==",
+ "Sec-WebSocket-Extensions": "permessage-deflate; client_max_window_bits",
+ "name": "HTTP_DECODER_RESULT_1"
+ },
+ {
+ "Tuple4": "131.179.196.220.59631>131.179.196.46.9696",
+ "res_version": "1.1",
+ "res_status": "Switching Protocols",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 101,
+ "Connection": "upgrade",
+ "Sec-WebSocket-Accept": "FRh9fmH0UaoLdY5BSFO4hP2Pcjw=",
+ "Server": "WebSocket++/0.5.1",
+ "Upgrade": "websocket",
+ "name": "HTTP_DECODER_RESULT_2"
+ }
+] \ No newline at end of file