summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-04 12:04:24 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2015-01-04 12:17:24 +0200
commita0f0440394ac3b38105dfad09366f95011c5d8d3 (patch)
tree792051d88b376c60a449b291d66e45741b5569e7 /tests
parent50c67ecec4895f65ba684e4b46b4b70980a5be6a (diff)
Detect too large varint values when decoding.
Because Issue #139 now allows limiting integer fields, it is good to check the values received from other protobuf libraries against the lower limits.
Diffstat (limited to 'tests')
-rw-r--r--tests/decode_unittests/decode_unittests.c6
-rw-r--r--tests/intsizes/intsizes_unittests.c14
2 files changed, 17 insertions, 3 deletions
diff --git a/tests/decode_unittests/decode_unittests.c b/tests/decode_unittests/decode_unittests.c
index 8c12f1cd..47f0fbdb 100644
--- a/tests/decode_unittests/decode_unittests.c
+++ b/tests/decode_unittests/decode_unittests.c
@@ -123,16 +123,16 @@ int main()
}
{
- pb_istream_t s = S("\x01\xFF\xFF\x03");
+ pb_istream_t s = S("\x01\x00");
pb_field_t f = {1, PB_LTYPE_VARINT, 0, 0, 4, 0, 0};
uint32_t d;
COMMENT("Test pb_dec_varint using uint32_t")
TEST(pb_dec_varint(&s, &f, &d) && d == 1)
/* Verify that no more than data_size is written. */
- d = 0;
+ d = 0xFFFFFFFF;
f.data_size = 1;
- TEST(pb_dec_varint(&s, &f, &d) && (d == 0xFF || d == 0xFF000000))
+ TEST(pb_dec_varint(&s, &f, &d) && (d == 0xFFFFFF00 || d == 0x00FFFFFF))
}
{
diff --git a/tests/intsizes/intsizes_unittests.c b/tests/intsizes/intsizes_unittests.c
index 29cc7ab0..189825f7 100644
--- a/tests/intsizes/intsizes_unittests.c
+++ b/tests/intsizes/intsizes_unittests.c
@@ -101,6 +101,20 @@ int main()
INT32_MIN, 0, INT32_MIN,
INT64_MIN, 0, INT64_MIN, true);
+ COMMENT("Test overflow detection");
+ TEST_ROUNDTRIP(-129, 0, -128,
+ -32768, 0, -32768,
+ INT32_MIN, 0, INT32_MIN,
+ INT64_MIN, 0, INT64_MIN, false);
+ TEST_ROUNDTRIP(127, 256, 127,
+ 32767, 65535, 32767,
+ INT32_MAX, UINT32_MAX, INT32_MAX,
+ INT64_MAX, UINT64_MAX, INT64_MAX, false);
+ TEST_ROUNDTRIP(-128, 0, -128,
+ -32768, 0, -32769,
+ INT32_MIN, 0, INT32_MIN,
+ INT64_MIN, 0, INT64_MIN, false);
+
if (status != 0)
fprintf(stdout, "\n\nSome tests FAILED!\n");