summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSimon Josefsson <simon@josefsson.org>2012-03-14 00:20:16 +0100
committerSimon Josefsson <simon@josefsson.org>2012-03-14 00:34:11 +0100
commit6e534bf4fb3144be51c928ed3efcf9c36055c9c7 (patch)
tree6b210e0bfffff8c7251208ca603d90c3902e6f3f /tests
parent4b1805a021aa9abe74ba775aaaff84fc21ea07e9 (diff)
downloadlibtasn1-6e534bf4fb3144be51c928ed3efcf9c36055c9c7.tar.gz
libtasn1-6e534bf4fb3144be51c928ed3efcf9c36055c9c7.tar.bz2
libtasn1-6e534bf4fb3144be51c928ed3efcf9c36055c9c7.zip
Simplify overflow check.
Diffstat (limited to 'tests')
-rw-r--r--tests/Test_overflow.c70
1 files changed, 58 insertions, 12 deletions
diff --git a/tests/Test_overflow.c b/tests/Test_overflow.c
index 383f723..2136899 100644
--- a/tests/Test_overflow.c
+++ b/tests/Test_overflow.c
@@ -23,25 +23,71 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <limits.h>
#include "libtasn1.h"
int
main (void)
{
- unsigned char der[] = "\x84\x7F\xFF\xFF\xFF";
- long l;
- int len;
-
- l = asn1_get_length_der (der, sizeof der, &len);
-
- if (l == -3L)
- puts ("asn1_get_length_der rejected overflow OK");
- else
- {
- printf ("asn1_get_length_der overflow (l %lX len %X)\n", l, len);
- return 1;
+ /* Test that values larger than long are rejected. This has worked
+ fine with all versions of libtasn1. */
+ {
+ unsigned char der[] = "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF";
+ long l;
+ int len;
+
+ l = asn1_get_length_der (der, sizeof der, &len);
+
+ if (l == -2L)
+ puts ("OK: asn1_get_length_der bignum");
+ else
+ {
+ printf ("ERROR: asn1_get_length_der bignum (l %ld len %d)\n", l, len);
+ return 1;
+ }
+ }
+
+ /* Test that values larger than int but smaller than long are
+ rejected. This limitation was introduced with libtasn1 2.12. */
+ if (LONG_MAX > INT_MAX)
+ {
+ unsigned long num = ((long) UINT_MAX) << 2;
+ unsigned char der[20];
+ int der_len;
+ long l;
+ int len;
+
+ asn1_length_der (num, der, &der_len);
+
+ l = asn1_get_length_der (der, der_len, &len);
+
+ if (l == -2L)
+ puts ("OK: asn1_get_length_der intnum");
+ else
+ {
+ printf ("ERROR: asn1_get_length_der intnum (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 char der[] = "\x84\x7F\xFF\xFF\xFF";
+ long l;
+ int len;
+
+ l = asn1_get_length_der (der, sizeof 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;
+ }
+ }
+
return 0;
}