summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2016-12-26 15:24:04 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2016-12-26 15:24:04 +0000
commit9fa2d0724ea4d447b73ebb1f07972dfd82a4a97d (patch)
tree5464184ebd2bb9a773d0cdead071f90d8b82896e /regress/lib
parent508371c14525226133818a75cecbd7e6788ec540 (diff)
Ensure that after an i2d_SSL_SESSION() call, the passed pointer now points
to the end of the buffer.
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libssl/asn1/asn1test.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/regress/lib/libssl/asn1/asn1test.c b/regress/lib/libssl/asn1/asn1test.c
index 946c672d745..28cd3d827af 100644
--- a/regress/lib/libssl/asn1/asn1test.c
+++ b/regress/lib/libssl/asn1/asn1test.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1test.c,v 1.4 2016/12/21 15:13:29 jsing Exp $ */
+/* $OpenBSD: asn1test.c,v 1.5 2016/12/26 15:24:03 jsing Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
*
@@ -205,7 +205,7 @@ session_strcmp(const unsigned char *o1, const unsigned char *o2, size_t len)
static int
session_cmp(SSL_SESSION *s1, SSL_SESSION *s2)
{
- /* Compare two sessions, from the perspective of ASN1. */
+ /* Compare the ASN.1 encoded values from two sessions. */
if (s1->ssl_version != s2->ssl_version) {
fprintf(stderr, "ssl_version differs: %i != %i\n",
s1->ssl_version, s2->ssl_version);
@@ -320,17 +320,12 @@ do_ssl_asn1_test(int test_no, struct ssl_asn1_test *sat)
/* See if the test is expected to fail... */
if (sat->asn1_len == -1)
return (0);
-
+
if ((asn1 = malloc(len)) == NULL)
errx(1, "failed to allocate memory");
ap = asn1;
len = i2d_SSL_SESSION(&sat->session, &ap);
- if ((ap - asn1) > len) {
- fprintf(stderr, "FAIL: test %i overflowed ticket buffer "
- "(%i > %i)\n", test_no, (int)(ap - asn1), len);
- goto failed;
- }
/*
* Length *should* be the same, but check it again since the code
@@ -341,6 +336,12 @@ do_ssl_asn1_test(int test_no, struct ssl_asn1_test *sat)
"want %i\n", test_no, len, sat->asn1_len);
goto failed;
}
+ /* ap should now point at the end of the buffer. */
+ if (ap - asn1 != len) {
+ fprintf(stderr, "FAIL: test %i pointer increment does not "
+ "match length (%i != %i)\n", test_no, (int)(ap - asn1), len);
+ goto failed;
+ }
if (memcmp(asn1, &sat->asn1, len) != 0) {
fprintf(stderr, "FAIL: test %i - encoding differs:\n", test_no);