diff options
| author | George Kadianakis <desnacked@riseup.net> | 2016-07-01 13:36:06 +0300 |
|---|---|---|
| committer | George Kadianakis <desnacked@riseup.net> | 2016-07-01 13:36:06 +0300 |
| commit | b81135e9ebcfd327099199c208185bca056fa617 (patch) | |
| tree | cf669be3dce7ffeda9ea3a9ddef5081dd788e935 | |
| parent | adac54c4e0bbccc0be1b708ac0bc0545e9f949bd (diff) | |
Write WIP test for build_plaintext_padding()ticket18571_029_04_test
| -rw-r--r-- | src/or/hs_descriptor.c | 4 | ||||
| -rw-r--r-- | src/or/hs_descriptor.h | 3 | ||||
| -rw-r--r-- | src/test/test_hs_descriptor.c | 33 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/or/hs_descriptor.c b/src/or/hs_descriptor.c index f58d40eda..760a701fe 100644 --- a/src/or/hs_descriptor.c +++ b/src/or/hs_descriptor.c @@ -455,7 +455,7 @@ compute_padding_length(size_t srclen) size_t padding_len; /* Make sure we won't overflow. */ - tor_assert(srclen > (SIZE_T_CEILING - HS_DESC_PLAINTEXT_PADDING_MULTIPLE)); + tor_assert(srclen <= (SIZE_T_CEILING - HS_DESC_PLAINTEXT_PADDING_MULTIPLE)); /* Get the extra length we need to add. For example, if srclen is 234 bytes, * this will expand to (2 * 128) == 256 thus an extra 22 bytes. */ padding_len = CEIL_DIV(srclen, HS_DESC_PLAINTEXT_PADDING_MULTIPLE) * @@ -468,7 +468,7 @@ compute_padding_length(size_t srclen) /* Given a buffer, pad it up to the encrypted section padding requirement. Set * the newly allocated string in padded_out and return the length of the * padded buffer. */ -static size_t +STATIC size_t build_plaintext_padding(const char *plaintext, size_t plaintext_len, uint8_t **padded_out) { diff --git a/src/or/hs_descriptor.h b/src/or/hs_descriptor.h index c79b252db..86f60e014 100644 --- a/src/or/hs_descriptor.h +++ b/src/or/hs_descriptor.h @@ -192,6 +192,9 @@ STATIC char *encode_link_specifiers(const smartlist_t *specs); STATIC smartlist_t *decode_link_specifiers(const char *encoded); STATIC hs_desc_intro_point_t *decode_introduction_point(const char *text, const char *end); +STATIC size_t build_plaintext_padding(const char *plaintext, + size_t plaintext_len, + uint8_t **padded_out); #endif /* HS_DESCRIPTOR_PRIVATE */ diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c index 12a84562d..6834cc476 100644 --- a/src/test/test_hs_descriptor.c +++ b/src/test/test_hs_descriptor.c @@ -259,6 +259,36 @@ test_cert_encoding(void *arg) free(encoded); } +/* Test the descriptor padding. */ +static void +test_descriptor_padding(void *arg) +{ + char *plaintext; + size_t plaintext_len, padded_len; + uint8_t *padded_plaintext; + + (void) arg; + + { /* test #1: no padding */ + plaintext_len = 128; + plaintext = tor_malloc(plaintext_len); + padded_len = build_plaintext_padding(plaintext, plaintext_len, &padded_plaintext); + tt_int_op(padded_len, ==, plaintext_len); + tor_free(plaintext); + } + + { /* test #1: one byte padding? */ + plaintext_len = 127; + plaintext = tor_malloc(plaintext_len); + padded_len = build_plaintext_padding(plaintext, plaintext_len, &padded_plaintext); + tt_int_op(padded_len, ==, 128); + tor_free(plaintext); + } + + + done: ; +} + static void test_link_specifier(void *arg) { @@ -388,6 +418,9 @@ struct testcase_t hs_descriptor[] = { NULL, NULL }, { "decode_descriptor", test_decode_descriptor, TT_FORK, NULL, NULL }, + { "descriptor_padding", test_descriptor_padding, TT_FORK, + NULL, NULL }, + END_OF_TESTCASES }; |
