summaryrefslogtreecommitdiff
path: root/src/regress/lib
diff options
context:
space:
mode:
authorjsing <>2022-06-25 15:49:28 +0000
committerjsing <>2022-06-25 15:49:28 +0000
commit3ab41ace1e3881927ef311ca2f0e8f2a30cf07a1 (patch)
treec2cd8bdd1184214f2768ac21fb14ff604c86cec9 /src/regress/lib
parent054c5de2e852004e06211ff00af4c880504a256f (diff)
downloadopenbsd-3ab41ace1e3881927ef311ca2f0e8f2a30cf07a1.tar.gz
openbsd-3ab41ace1e3881927ef311ca2f0e8f2a30cf07a1.tar.bz2
openbsd-3ab41ace1e3881927ef311ca2f0e8f2a30cf07a1.zip
Check pointer argument after {d2i,i2d}_ASN1_{BIT_STRING,BOOLEAN,INTEGER}()
Diffstat (limited to 'src/regress/lib')
-rw-r--r--src/regress/lib/libcrypto/asn1/asn1basic.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c
index e46f9430a6..f3b768407d 100644
--- a/src/regress/lib/libcrypto/asn1/asn1basic.c
+++ b/src/regress/lib/libcrypto/asn1/asn1basic.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: asn1basic.c,v 1.8 2022/06/25 15:41:14 jsing Exp $ */ 1/* $OpenBSD: asn1basic.c,v 1.9 2022/06/25 15:49:28 jsing Exp $ */
2/* 2/*
3 * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> 3 * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org>
4 * 4 *
@@ -94,10 +94,14 @@ asn1_bit_string_test(void)
94 fprintf(stderr, "FAIL: i2d_ASN1_BIT_STRING\n"); 94 fprintf(stderr, "FAIL: i2d_ASN1_BIT_STRING\n");
95 goto failed; 95 goto failed;
96 } 96 }
97
98 if (!asn1_compare_bytes("BIT_STRING", p, len, asn1_bit_string_primitive, 97 if (!asn1_compare_bytes("BIT_STRING", p, len, asn1_bit_string_primitive,
99 sizeof(asn1_bit_string_primitive))) 98 sizeof(asn1_bit_string_primitive)))
100 goto failed; 99 goto failed;
100 if (pp != p + len) {
101 fprintf(stderr, "FAIL: i2d_ASN1_BIT_STRING pp = %p, want %p\n",
102 pp, p + len);
103 goto failed;
104 }
101 105
102 /* Test primitive decoding. */ 106 /* Test primitive decoding. */
103 q = p; 107 q = p;
@@ -108,6 +112,11 @@ asn1_bit_string_test(void)
108 if (!asn1_compare_bytes("BIT_STRING primitive data", abs->data, abs->length, 112 if (!asn1_compare_bytes("BIT_STRING primitive data", abs->data, abs->length,
109 bs, sizeof(bs))) 113 bs, sizeof(bs)))
110 goto failed; 114 goto failed;
115 if (q != p + len) {
116 fprintf(stderr, "FAIL: d2i_ASN1_BIT_STRING q = %p, want %p\n",
117 q, p + len);
118 goto failed;
119 }
111 120
112 /* Test ASN1_BIT_STRING_get_bit(). */ 121 /* Test ASN1_BIT_STRING_get_bit(). */
113 for (i = 0; i < ((int)sizeof(bs) * 8); i++) { 122 for (i = 0; i < ((int)sizeof(bs) * 8); i++) {
@@ -190,6 +199,11 @@ asn1_boolean_test(void)
190 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN false\n"); 199 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN false\n");
191 goto failed; 200 goto failed;
192 } 201 }
202 if (pp != p + len) {
203 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN pp = %p, want %p\n",
204 pp, p + len);
205 goto failed;
206 }
193 207
194 if (!asn1_compare_bytes("BOOLEAN false", p, len, asn1_boolean_false, 208 if (!asn1_compare_bytes("BOOLEAN false", p, len, asn1_boolean_false,
195 sizeof(asn1_boolean_false))) 209 sizeof(asn1_boolean_false)))
@@ -200,6 +214,11 @@ asn1_boolean_test(void)
200 fprintf(stderr, "FAIL: BOOLEAN false did not decode to 0\n"); 214 fprintf(stderr, "FAIL: BOOLEAN false did not decode to 0\n");
201 goto failed; 215 goto failed;
202 } 216 }
217 if (q != p + len) {
218 fprintf(stderr, "FAIL: d2i_ASN1_BOOLEAN q = %p, want %p\n",
219 q, p + len);
220 goto failed;
221 }
203 222
204 free(p); 223 free(p);
205 p = NULL; 224 p = NULL;
@@ -215,6 +234,11 @@ asn1_boolean_test(void)
215 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN true\n"); 234 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN true\n");
216 goto failed; 235 goto failed;
217 } 236 }
237 if (pp != p + len) {
238 fprintf(stderr, "FAIL: i2d_ASN1_BOOLEAN pp = %p, want %p\n",
239 pp, p + len);
240 goto failed;
241 }
218 242
219 if (!asn1_compare_bytes("BOOLEAN true", p, len, asn1_boolean_true, 243 if (!asn1_compare_bytes("BOOLEAN true", p, len, asn1_boolean_true,
220 sizeof(asn1_boolean_true))) 244 sizeof(asn1_boolean_true)))
@@ -225,6 +249,11 @@ asn1_boolean_test(void)
225 fprintf(stderr, "FAIL: BOOLEAN true did not decode to 1\n"); 249 fprintf(stderr, "FAIL: BOOLEAN true did not decode to 1\n");
226 goto failed; 250 goto failed;
227 } 251 }
252 if (q != p + len) {
253 fprintf(stderr, "FAIL: d2i_ASN1_BOOLEAN q = %p, want %p\n",
254 q, p + len);
255 goto failed;
256 }
228 257
229 failed = 0; 258 failed = 0;
230 259
@@ -360,6 +389,11 @@ asn1_integer_set_test(struct asn1_integer_test *ait)
360 fprintf(stderr, "FAIL: Not V_ASN1_NEG_INTEGER\n"); 389 fprintf(stderr, "FAIL: Not V_ASN1_NEG_INTEGER\n");
361 goto failed; 390 goto failed;
362 } 391 }
392 if (ASN1_INTEGER_get(aint) != ait->value) {
393 fprintf(stderr, "FAIL: ASN1_INTEGER_get() = %ld, want %ld\n",
394 ASN1_INTEGER_get(aint), ait->value);
395 goto failed;
396 }
363 if ((len = i2d_ASN1_INTEGER(aint, NULL)) < 0) { 397 if ((len = i2d_ASN1_INTEGER(aint, NULL)) < 0) {
364 fprintf(stderr, "FAIL: i2d_ASN1_INTEGER() failed\n"); 398 fprintf(stderr, "FAIL: i2d_ASN1_INTEGER() failed\n");
365 goto failed; 399 goto failed;
@@ -419,6 +453,11 @@ asn1_integer_content_test(struct asn1_integer_test *ait)
419 if (!asn1_compare_bytes("INTEGER content", p, len, ait->der, 453 if (!asn1_compare_bytes("INTEGER content", p, len, ait->der,
420 ait->der_len)) 454 ait->der_len))
421 goto failed; 455 goto failed;
456 if (pp != p + len) {
457 fprintf(stderr, "FAIL: i2d_ASN1_INTEGER pp = %p, want %p\n",
458 pp, p + len);
459 goto failed;
460 }
422 461
423 failed = 0; 462 failed = 0;
424 463
@@ -446,6 +485,11 @@ asn1_integer_decode_test(struct asn1_integer_test *ait)
446 if (!asn1_compare_bytes("INTEGER content", aint->data, 485 if (!asn1_compare_bytes("INTEGER content", aint->data,
447 aint->length, ait->content, ait->content_len)) 486 aint->length, ait->content, ait->content_len))
448 goto failed; 487 goto failed;
488 if (q != ait->der + ait->der_len) {
489 fprintf(stderr, "FAIL: d2i_ASN1_INTEGER q = %p, want %p\n",
490 q, ait->der + ait->der_len);
491 goto failed;
492 }
449 } else if (ait->want_error == 0) { 493 } else if (ait->want_error == 0) {
450 fprintf(stderr, "FAIL: INTEGER failed to decode\n"); 494 fprintf(stderr, "FAIL: INTEGER failed to decode\n");
451 goto failed; 495 goto failed;