summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2024-08-10 17:05:23 +0800
committerlijia <[email protected]>2024-08-10 17:05:23 +0800
commit2a1ca8defbc5b461f4a6a40a2f4b98653eea007b (patch)
treefe677e00b63023575cb197f6e16a56d20e062549
parentd27dc94f3d64f698c06bcb671364d923a878b7ed (diff)
fix zlib inflate dead loop
-rw-r--r--src/http_content_decompress.cpp4
-rw-r--r--src/http_decoder.cpp14
-rw-r--r--test/http_pcap/http_zlib_deadlock.pcapbin0 -> 3756 bytes
-rw-r--r--test/test_result_json/http_zlib_deadlock.json42
-rw-r--r--test_based_on_stellar/CMakeLists.txt2
-rw-r--r--test_based_on_stellar/plugin_test_main.cpp27
6 files changed, 73 insertions, 16 deletions
diff --git a/src/http_content_decompress.cpp b/src/http_content_decompress.cpp
index 44fcdf3..0ecd9ca 100644
--- a/src/http_content_decompress.cpp
+++ b/src/http_content_decompress.cpp
@@ -163,8 +163,10 @@ http_content_decompress_write_zlib(struct http_content_decompress *decompress,
*outdata_len = have;
}
}
+ if(Z_STREAM_END == ret){
+ break;
+ }
} while (z_stream_ptr->avail_in != 0);
-
return 0;
}
diff --git a/src/http_decoder.cpp b/src/http_decoder.cpp
index 1b177d9..640217b 100644
--- a/src/http_decoder.cpp
+++ b/src/http_decoder.cpp
@@ -580,13 +580,14 @@ extern "C"
stellar_session_plugin_dettach_current_session(sess);
return (void *)HTTP_CTX_NOT_HTTP;
}
-
struct http_decoder_exdata *exdata = httpd_session_exdata_new(sess, httpd_env, 0, 0);
exdata->pub_topic_id = httpd_env->topic_exdata_compose[HTTPD_TOPIC_HTTP_MSG_INDEX].sub_topic_id;
session_exdata_set(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id, exdata);
+ return (void *)HTTP_CTX_IS_HTTP;
}
- return (void *)HTTP_CTX_IS_HTTP;
+ stellar_session_plugin_dettach_current_session(sess);
+ return (void *)HTTP_CTX_NOT_HTTP;
}
void httpd_session_ctx_free_cb(struct session *sess, void *session_ctx, void *plugin_env)
@@ -740,9 +741,14 @@ extern "C"
enum session_state sess_state = session_get_current_state(sess);
struct http_decoder_exdata *exdata = (struct http_decoder_exdata *)session_exdata_get(sess, httpd_env->topic_exdata_compose[HTTPD_TOPIC_TCP_STREAM_INDEX].exdata_id);
- assert (NULL != exdata);
+ if (NULL == exdata)
+ {
+ http_decoder_stat_update(&httpd_env->hd_stat, stellar_get_current_thread_index(), HTTPD_STAT_PARSE_ERR, 1);
+ stellar_session_plugin_dettach_current_session(sess);
+ return;
+ }
- if(SESSION_STATE_CLOSED == sess_state)
+ if (SESSION_STATE_CLOSED == sess_state)
{
if (httpd_in_tunnel_transmitting(exdata))
{
diff --git a/test/http_pcap/http_zlib_deadlock.pcap b/test/http_pcap/http_zlib_deadlock.pcap
new file mode 100644
index 0000000..05862f8
--- /dev/null
+++ b/test/http_pcap/http_zlib_deadlock.pcap
Binary files differ
diff --git a/test/test_result_json/http_zlib_deadlock.json b/test/test_result_json/http_zlib_deadlock.json
new file mode 100644
index 0000000..db350cd
--- /dev/null
+++ b/test/test_result_json/http_zlib_deadlock.json
@@ -0,0 +1,42 @@
+[
+ {
+ "__X_HTTP_TUPLE4": "100.107.59.2:47242-106.122.255.251:80-6-0"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "request",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "method": "GET",
+ "uri": "/xmlymain-login-web/login/ts-1657244122966?appId=mainApp&appStatus=2&clientType=android&isFirstReq=false&lastSuccessIp=180.153.250.247:3814&userId=175776850",
+ "req_version": "1.1",
+ "major_version": 1,
+ "minor_version": 1,
+ "Cookie2": "$version=1",
+ "Accept": "*/*",
+ "user-agent": "ting_xmim1.0(Mi+10,Android29)",
+ "xmTraceId": "f30c74a5-c62d-46a0-80bd-d51dbf139976163",
+ "Host": "xmc.ximalaya.com",
+ "Connection": "Keep-Alive",
+ "Accept-Encoding": "gzip",
+ "__X_HTTP_URL": "xmc.ximalaya.com/xmlymain-login-web/login/ts-1657244122966?appId=mainApp&appStatus=2&clientType=android&isFirstReq=false&lastSuccessIp=180.153.250.247:3814&userId=175776850"
+ },
+ {
+ "__X_HTTP_TRANSACTION": "response",
+ "__X_HTTP_TRANSACTION_SEQ": 0,
+ "res_version": "1.1",
+ "res_status": "OK",
+ "major_version": 1,
+ "minor_version": 1,
+ "status_code": 200,
+ "Server": "Tengine",
+ "Date": "Fri, 08 Jul 2022 01:35:24 GMT",
+ "Content-Type": "application/json;charset=UTF-8",
+ "Vary": "Accept-Encoding",
+ "x-idc-gw": "0",
+ "Content-Encoding": "gzip",
+ "Transfer-Encoding": "chunked",
+ "X-NWS-LOG-UUID": "12197298277844186084",
+ "Connection": "keep-alive",
+ "X-Cache-Lookup": "Cache Miss",
+ "__X_HTTP_PAYLOAD_MD5": "d383effc464d797b5fdb4d98f4ab0111"
+ }
+] \ No newline at end of file
diff --git a/test_based_on_stellar/CMakeLists.txt b/test_based_on_stellar/CMakeLists.txt
index 61fe798..af1757c 100644
--- a/test_based_on_stellar/CMakeLists.txt
+++ b/test_based_on_stellar/CMakeLists.txt
@@ -85,6 +85,7 @@ add_test(NAME STELLAR_HTTP_FIN_TEST COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http
# add_test(NAME STELLAR_HTTP_TUNNEL_ONLY_HDR_TEST COMMAND ./${TEST_MAIN} ${TEST_JSON_DIR}/http_tunnel_s2c_only_hdr.json
# -r ${TEST_PCAP_DIR}/http_tunnel_s2c_only_hdr.pcap WORKING_DIRECTORY ${TEST_RUN_DIR})
add_test(NAME STELLAR_HTTP_CHN_ENCODE_URL COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_chn_encode_url.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_chn_encode_url.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
+add_test(NAME STELLAR_HTTP_ZLIB_DEADLOCK COMMAND sh -c "ln -sf ${TEST_PCAP_DIR}/http_zlib_deadlock.pcap ${TEST_RUN_DIR}/pcap/test.pcap; ./${TEST_MAIN} ${TEST_JSON_DIR}/http_zlib_deadlock.json" WORKING_DIRECTORY ${TEST_RUN_DIR})
set_tests_properties(STELLAR_HTTP_GET_SINGLE_TRANS_TEST
STELLAR_HTTP_GET_MULTI_TRANS_TEST
@@ -108,6 +109,7 @@ set_tests_properties(STELLAR_HTTP_GET_SINGLE_TRANS_TEST
STELLAR_HTTP_TRANS_PIPELINE_TEST
STELLAR_HTTP_FIN_TEST
STELLAR_HTTP_CHN_ENCODE_URL
+ STELLAR_HTTP_ZLIB_DEADLOCK
PROPERTIES FIXTURES_REQUIRED TestFixture)
add_test(NAME UPDATE_STATE_PLUG_ENTRY COMMAND bash -c "sed -i 's/name=.*/name=\\x22http_decoder_test_state_entry\\x22/' ${TEST_RUN_DIR}/etc/http/gtest_entry.toml")
diff --git a/test_based_on_stellar/plugin_test_main.cpp b/test_based_on_stellar/plugin_test_main.cpp
index 37d6f4e..f13ae62 100644
--- a/test_based_on_stellar/plugin_test_main.cpp
+++ b/test_based_on_stellar/plugin_test_main.cpp
@@ -20,9 +20,9 @@ extern "C"
#define printf(fmt, ...) (0)
#endif
-cJSON *g_test_result_root = NULL;
-cJSON *g_load_result_root = NULL;
-int g_ret = 0;
+static cJSON *g_test_result_root = NULL;
+static cJSON *g_load_result_root = NULL;
+static const char *result_json_path = NULL;
extern "C" int commit_test_result_json(cJSON *node, const char *name)
{
@@ -128,18 +128,23 @@ int main(int argc, char *argv[])
if (argc < 2)
{
printf("Usage: %s <result_json_path>\n", argv[0]);
- return -1;
+ result_json_path = NULL;
+ }
+ else
+ {
+ result_json_path = argv[1];
+ g_test_result_root = cJSON_CreateArray();
+ g_load_result_root = load_result_from_jsonfile(result_json_path);
+ assert(g_load_result_root != NULL && g_test_result_root != NULL);
}
- const char *result_json_path = argv[1];
- g_test_result_root = cJSON_CreateArray();
- g_load_result_root = load_result_from_jsonfile(result_json_path);
- assert(g_load_result_root != NULL && g_test_result_root != NULL);
::testing::InitGoogleTest(&argc, argv);
-
if (stellar_run(argc - 1, argv + 1) < 0)
{
return -1;
}
-
- return RUN_ALL_TESTS();
+ if (result_json_path != NULL)
+ {
+ RUN_ALL_TESTS();
+ }
+ return 0;
}