diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-02-13 09:39:46 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-02-14 16:38:47 -0500 |
commit | c4f2faf3019f2c41f9c3b2b8a73b4fe41e881328 (patch) | |
tree | ddb5cd77c06a5dda60a8f7683bcd6b2ce506c601 /src/test | |
parent | 4a2afd5b33f02ed3e5eb591dd29537fa4f69399f (diff) | |
download | tor-c4f2faf3019f2c41f9c3b2b8a73b4fe41e881328.tar.gz tor-c4f2faf3019f2c41f9c3b2b8a73b4fe41e881328.zip |
Don't atoi off the end of a buffer chunk.
Fixes bug 20894; bugfix on 0.2.0.16-alpha.
We already applied a workaround for this as 20834, so no need to
freak out (unless you didn't apply 20384 yet).
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_buffers.c | 44 | ||||
-rw-r--r-- | src/test/test_util.c | 1 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/test/test_buffers.c b/src/test/test_buffers.c index 3408da3aa9..9e7bdb8911 100644 --- a/src/test/test_buffers.c +++ b/src/test/test_buffers.c @@ -765,6 +765,49 @@ test_buffers_chunk_size(void *arg) ; } +static void +test_buffers_find_contentlen(void *arg) +{ + static const struct { + const char *headers; + int r; + int contentlen; + } results[] = { + { "Blah blah\r\nContent-Length: 1\r\n\r\n", 1, 1 }, + { "Blah blah\r\n\r\n", 0, 0 }, /* no content-len */ + { "Blah blah Content-Length: 1\r\n", 0, 0 }, /* no content-len. */ + { "Blah blah\r\nContent-Length: 100000\r\n", 1, 100000}, + { "Blah blah\r\nContent-Length: 1000000000000000000000000\r\n", -1, 0}, + { "Blah blah\r\nContent-Length: 0\r\n", 1, 0}, + { "Blah blah\r\nContent-Length: -1\r\n", -1, 0}, + { "Blah blah\r\nContent-Length: 1x\r\n", -1, 0}, + { "Blah blah\r\nContent-Length: 1 x\r\n", -1, 0}, + { "Blah blah\r\nContent-Length: 1 \r\n", 1, 1}, + { "Blah blah\r\nContent-Length: \r\n", -1, 0}, + { "Blah blah\r\nContent-Length: ", -1, 0}, + { "Blah blah\r\nContent-Length: 5050", -1, 0}, + { NULL, 0, 0 } + }; + int i; + + (void)arg; + + for (i = 0; results[i].headers; ++i) { + int r; + size_t sz; + size_t headerlen = strlen(results[i].headers); + char * tmp = tor_memdup(results[i].headers, headerlen);/* ensure no eos */ + sz = 999; /* to ensure it gets set */ + r = buf_http_find_content_length(tmp, headerlen, &sz); + tor_free(tmp); + log_debug(LD_DIR, "%d: %s", i, escaped(results[i].headers)); + tt_int_op(r, ==, results[i].r); + tt_int_op(sz, ==, results[i].contentlen); + } + done: + ; +} + struct testcase_t buffer_tests[] = { { "basic", test_buffers_basic, TT_FORK, NULL, NULL }, { "copy", test_buffer_copy, TT_FORK, NULL, NULL }, @@ -780,6 +823,7 @@ struct testcase_t buffer_tests[] = { { "tls_read_mocked", test_buffers_tls_read_mocked, 0, NULL, NULL }, { "chunk_size", test_buffers_chunk_size, 0, NULL, NULL }, + { "find_contentlen", test_buffers_find_contentlen, 0, NULL, NULL }, END_OF_TESTCASES }; diff --git a/src/test/test_util.c b/src/test/test_util.c index fcda564569..dc01d1a94b 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -9,6 +9,7 @@ #define CONTROL_PRIVATE #define UTIL_PRIVATE #include "or.h" +#include "buffers.h" #include "config.h" #include "control.h" #include "test.h" |