From 252aeb43e1e11c1974b8a56f77a94468135ab87a Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 15 May 2015 01:00:09 +0900 Subject: [PATCH] Add test for GH-232 --- tests/main.c | 2 ++ tests/nghttp2_buf_test.c | 20 ++++++++++++++++++++ tests/nghttp2_buf_test.h | 1 + 3 files changed, 23 insertions(+) diff --git a/tests/main.c b/tests/main.c index 933da918..ae42e70c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -340,6 +340,8 @@ int main(int argc _U_, char *argv[] _U_) { !CU_add_test(pSuite, "check_header_value", test_nghttp2_check_header_value) || !CU_add_test(pSuite, "bufs_add", test_nghttp2_bufs_add) || + !CU_add_test(pSuite, "bufs_add_stack_buffer_overflow_bug", + test_nghttp2_bufs_add_stack_buffer_overflow_bug) || !CU_add_test(pSuite, "bufs_addb", test_nghttp2_bufs_addb) || !CU_add_test(pSuite, "bufs_orb", test_nghttp2_bufs_orb) || !CU_add_test(pSuite, "bufs_remove", test_nghttp2_bufs_remove) || diff --git a/tests/nghttp2_buf_test.c b/tests/nghttp2_buf_test.c index 01f31fcf..8860554f 100644 --- a/tests/nghttp2_buf_test.c +++ b/tests/nghttp2_buf_test.c @@ -63,6 +63,26 @@ void test_nghttp2_bufs_add(void) { nghttp2_bufs_free(&bufs); } +/* Test for GH-232, stack-buffer-overflow */ +void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void) { + int rv; + nghttp2_bufs bufs; + uint8_t data[1024]; + nghttp2_mem *mem; + + mem = nghttp2_mem_default(); + + rv = nghttp2_bufs_init(&bufs, 100, 200, mem); + CU_ASSERT(0 == rv); + + rv = nghttp2_bufs_add(&bufs, data, sizeof(data)); + + CU_ASSERT(0 == rv); + CU_ASSERT(sizeof(data) == nghttp2_bufs_len(&bufs)); + + nghttp2_bufs_free(&bufs); +} + void test_nghttp2_bufs_addb(void) { int rv; nghttp2_bufs bufs; diff --git a/tests/nghttp2_buf_test.h b/tests/nghttp2_buf_test.h index 5da388e7..0b94a3f4 100644 --- a/tests/nghttp2_buf_test.h +++ b/tests/nghttp2_buf_test.h @@ -26,6 +26,7 @@ #define NGHTTP2_BUF_TEST_H void test_nghttp2_bufs_add(void); +void test_nghttp2_bufs_add_stack_buffer_overflow_bug(void); void test_nghttp2_bufs_addb(void); void test_nghttp2_bufs_orb(void); void test_nghttp2_bufs_remove(void);