aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/transport/chttp2
diff options
context:
space:
mode:
authorGravatar Yuchen Zeng <zyc@google.com>2016-05-13 17:23:07 -0700
committerGravatar Yuchen Zeng <zyc@google.com>2016-05-13 17:23:07 -0700
commit5833c706dbff35a55465db4405cf0ac035c63abe (patch)
tree64d73075dc9e043d2bf3ee3a3c76b83209396199 /test/core/transport/chttp2
parentd982bba41d8676f33431d540d8a4b0c15e426f1c (diff)
Add incremental decoding and input validation
Diffstat (limited to 'test/core/transport/chttp2')
-rw-r--r--test/core/transport/chttp2/bin_decoder_test.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/test/core/transport/chttp2/bin_decoder_test.c b/test/core/transport/chttp2/bin_decoder_test.c
index 980da02dc3..c4e6cd332f 100644
--- a/test/core/transport/chttp2/bin_decoder_test.c
+++ b/test/core/transport/chttp2/bin_decoder_test.c
@@ -37,7 +37,6 @@
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
-#include <grpc/support/log.h>
#include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
#include "src/core/lib/support/string.h"
@@ -72,6 +71,14 @@ static gpr_slice base64_decode(const char *s) {
return out;
}
+static gpr_slice base64_decode_with_length(const char *s,
+ size_t output_length) {
+ gpr_slice ss = gpr_slice_from_copied_string(s);
+ gpr_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length);
+ gpr_slice_unref(ss);
+ return out;
+}
+
#define EXPECT_SLICE_EQ(expected, slice) \
expect_slice_eq( \
gpr_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \
@@ -82,11 +89,9 @@ static gpr_slice base64_decode(const char *s) {
s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s)));
int main(int argc, char **argv) {
- /*
- * ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which
- * takes encoded base64 strings without pad chars, but output length is
- * required
- */
+ /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which
+ takes encoded base64 strings without pad chars, but output length is
+ required. */
/* Base64 test vectors from RFC 4648 */
ENCODE_AND_DECODE("");
ENCODE_AND_DECODE("f");
@@ -116,5 +121,24 @@ int main(int argc, char **argv) {
EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF"));
+ // Test illegal input length in grpc_chttp2_base64_decode
+ EXPECT_SLICE_EQ("", base64_decode("a"));
+ EXPECT_SLICE_EQ("", base64_decode("ab"));
+ EXPECT_SLICE_EQ("", base64_decode("abc"));
+
+ // Test illegal charactors in grpc_chttp2_base64_decode
+ EXPECT_SLICE_EQ("", base64_decode("Zm:v"));
+ EXPECT_SLICE_EQ("", base64_decode("Zm=v"));
+
+ // Test output_length longer than max possible output length in
+ // grpc_chttp2_base64_decode_with_length
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4));
+
+ // Test illegal charactors in grpc_chttp2_base64_decode_with_length
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3));
+
return all_ok ? 0 : 1;
}