summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2012-03-31 20:16:48 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2012-03-31 20:17:39 +0200
commit3873c6a49122e3f15901646e072938557acd3f8e (patch)
tree579e34f56b7e0a87db27d134e928230e4e4bad5e /tests
parent95ed3fdda525edd37ce0ea8eaf255a9b1563a25b (diff)
downloadlibtasn1-3873c6a49122e3f15901646e072938557acd3f8e.tar.gz
libtasn1-3873c6a49122e3f15901646e072938557acd3f8e.tar.bz2
libtasn1-3873c6a49122e3f15901646e072938557acd3f8e.zip
Added overflow detection that does not depend on specific compiler, and asn1_get_der_length() verifies the length of the input data in small numbers as well.
Diffstat (limited to 'tests')
-rw-r--r--tests/Test_overflow.c57
1 files changed, 43 insertions, 14 deletions
diff --git a/tests/Test_overflow.c b/tests/Test_overflow.c
index 747507f..bd6ede7 100644
--- a/tests/Test_overflow.c
+++ b/tests/Test_overflow.c
@@ -74,22 +74,51 @@ main (void)
/* Test that values larger than would fit in the input string are
rejected. This problem was fixed in libtasn1 2.12. */
- {
- unsigned char der[] = "\x84\x7F\xFF\xFF\xFF";
- long l;
- int len;
+ {
+ unsigned long num = 64;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
- l = asn1_get_length_der (der, sizeof der, &len);
+ asn1_length_der (num, der, &der_len);
- if (l == -4L)
- puts ("OK: asn1_get_length_der overflow");
- else
- {
- printf ("ERROR: asn1_get_length_der overflow (l %ld len %d)\n", l,
- len);
- return 1;
- }
- }
+ der_len = sizeof(der);
+ l = asn1_get_length_der (der, der_len, &len);
+
+ if (l == -4L)
+ puts ("OK: asn1_get_length_der overflow-small");
+ else
+ {
+ printf ("ERROR: asn1_get_length_der overflow-small (l %ld len %d)\n", l,
+ len);
+ return 1;
+ }
+ }
+
+ /* Test that values larger than would fit in the input string are
+ rejected. This problem was fixed in libtasn1 2.12. */
+ {
+ unsigned long num = 2147483647;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
+
+ asn1_length_der (num, der, &der_len);
+
+ der_len = sizeof(der);
+ l = asn1_get_length_der (der, der_len, &len);
+
+ if (l == -2L)
+ puts ("OK: asn1_get_length_der overflow-large");
+ else
+ {
+ printf ("ERROR: asn1_get_length_der overflow-large (l %ld len %d)\n", l,
+ len);
+ return 1;
+ }
+ }
return 0;
}