summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2024-05-29 16:47:27 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2024-05-29 16:47:27 +0000
commit83a1c534cbd79f1125f7ce1ec2f83714ccc526f4 (patch)
tree7ecd6b3d87a2e8ee21a10013bfcb847b28de0b84 /regress/lib
parent01e4c1998bb6a839a476fff0450326a362ceee4f (diff)
Add regress coverage for some corner cases of i2d_ASN1_OBJECT()
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libcrypto/asn1/asn1object.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/regress/lib/libcrypto/asn1/asn1object.c b/regress/lib/libcrypto/asn1/asn1object.c
index 56382a4edc5..0660f8af7db 100644
--- a/regress/lib/libcrypto/asn1/asn1object.c
+++ b/regress/lib/libcrypto/asn1/asn1object.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: asn1object.c,v 1.11 2024/05/29 16:19:50 tb Exp $ */
+/* $OpenBSD: asn1object.c,v 1.12 2024/05/29 16:47:26 tb Exp $ */
/*
* Copyright (c) 2017, 2021, 2022 Joel Sing <jsing@openbsd.org>
*
@@ -17,6 +17,7 @@
#include <openssl/asn1.h>
#include <openssl/err.h>
+#include <openssl/objects.h>
#include <err.h>
#include <stdio.h>
@@ -505,6 +506,43 @@ asn1_object_large_oid_test(void)
return failed;
}
+static int
+asn1_object_i2d_errors(void)
+{
+ ASN1_OBJECT *aobj = NULL;
+ int ret;
+ int failed = 1;
+
+ if ((ret = i2d_ASN1_OBJECT(NULL, NULL)) > 0) {
+ fprintf(stderr, "FAIL: i2d_ASN1_OBJECT(NULL, NULL) returned %d, "
+ "want <= 0\n", ret);
+ goto failed;
+ }
+
+ if ((aobj = OBJ_nid2obj(NID_undef)) == NULL) {
+ fprintf(stderr, "FAIL: OBJ_nid2obj() failed\n");
+ goto failed;
+ }
+
+ if (OBJ_get0_data(aobj) != NULL) {
+ fprintf(stderr, "FAIL: undefined obj didn't have NULL data\n");
+ goto failed;
+ }
+
+ if ((ret = i2d_ASN1_OBJECT(aobj, NULL)) > 0) {
+ fprintf(stderr, "FAIL: i2d_ASN1_OBJECT() succeeded on undefined "
+ "object\n");
+ goto failed;
+ }
+
+ failed = 0;
+
+ failed:
+ ASN1_OBJECT_free(aobj);
+
+ return failed;
+}
+
int
main(int argc, char **argv)
{
@@ -514,6 +552,7 @@ main(int argc, char **argv)
failed |= asn1_object_bad_content_test();
failed |= asn1_object_txt_test();
failed |= asn1_object_large_oid_test();
+ failed |= asn1_object_i2d_errors();
return (failed);
}