Skip to content

Commit 26f53b0

Browse files
committed
tests: internal: cover invalid chunked size lines
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent bd507b3 commit 26f53b0

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

tests/internal/http_client.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,72 @@ void test_http_response_chunked_multi_stage_trailers()
974974
test_ctx_destroy(ctx);
975975
}
976976

977+
void test_http_response_chunked_invalid_size_suffix()
978+
{
979+
int ret;
980+
struct test_ctx *ctx;
981+
struct flb_http_client *c;
982+
983+
ctx = test_ctx_create();
984+
if (!TEST_CHECK(ctx != NULL)) {
985+
exit(EXIT_FAILURE);
986+
}
987+
988+
c = flb_http_client(ctx->u_conn, FLB_HTTP_GET, "/", NULL, 0,
989+
"127.0.0.1", 80, NULL, FLB_HTTP_11);
990+
if (!TEST_CHECK(c != NULL)) {
991+
TEST_MSG("flb_http_client failed");
992+
test_ctx_destroy(ctx);
993+
exit(EXIT_FAILURE);
994+
}
995+
996+
append_response_fragment(c,
997+
"HTTP/1.1 200 OK\r\n"
998+
"Transfer-Encoding: chunked\r\n"
999+
"\r\n"
1000+
"1g\r\n"
1001+
"A\r\n"
1002+
"0\r\n\r\n");
1003+
1004+
ret = flb_http_client_process_response_buffer(c);
1005+
TEST_CHECK(ret == FLB_HTTP_ERROR);
1006+
1007+
flb_http_client_destroy(c);
1008+
test_ctx_destroy(ctx);
1009+
}
1010+
1011+
void test_http_response_chunked_oversized_length()
1012+
{
1013+
int ret;
1014+
struct test_ctx *ctx;
1015+
struct flb_http_client *c;
1016+
1017+
ctx = test_ctx_create();
1018+
if (!TEST_CHECK(ctx != NULL)) {
1019+
exit(EXIT_FAILURE);
1020+
}
1021+
1022+
c = flb_http_client(ctx->u_conn, FLB_HTTP_GET, "/", NULL, 0,
1023+
"127.0.0.1", 80, NULL, FLB_HTTP_11);
1024+
if (!TEST_CHECK(c != NULL)) {
1025+
TEST_MSG("flb_http_client failed");
1026+
test_ctx_destroy(ctx);
1027+
exit(EXIT_FAILURE);
1028+
}
1029+
1030+
append_response_fragment(c,
1031+
"HTTP/1.1 200 OK\r\n"
1032+
"Transfer-Encoding: chunked\r\n"
1033+
"\r\n"
1034+
"ffffffffffffffffffffffffffffffff\r\n");
1035+
1036+
ret = flb_http_client_process_response_buffer(c);
1037+
TEST_CHECK(ret == FLB_HTTP_ERROR);
1038+
1039+
flb_http_client_destroy(c);
1040+
test_ctx_destroy(ctx);
1041+
}
1042+
9771043
void test_http_timeout_setters_preserve_upstream_io_timeout()
9781044
{
9791045
struct test_ctx *ctx;
@@ -1040,6 +1106,8 @@ TEST_LIST = {
10401106
{ "response_chunked_empty_terminal_split", test_http_response_chunked_empty_terminal_split},
10411107
{ "response_chunked_uppercase_hex_whitespace", test_http_response_chunked_uppercase_hex_whitespace},
10421108
{ "response_chunked_multi_stage_trailers", test_http_response_chunked_multi_stage_trailers},
1109+
{ "response_chunked_invalid_size_suffix", test_http_response_chunked_invalid_size_suffix},
1110+
{ "response_chunked_oversized_length", test_http_response_chunked_oversized_length},
10431111
{ "timeout_setters_preserve_upstream_io_timeout", test_http_timeout_setters_preserve_upstream_io_timeout},
10441112
{ 0 }
10451113
};

0 commit comments

Comments
 (0)