From 6183aea1d172d808804400491565891daab7894a Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 23 May 2023 11:05:09 +0000 Subject: [PATCH] Add regress coverage for obj_dat.c r1.52 --- regress/lib/libcrypto/objects/objectstest.c | 45 ++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/regress/lib/libcrypto/objects/objectstest.c b/regress/lib/libcrypto/objects/objectstest.c index dba38644cfb..cb22709997f 100644 --- a/regress/lib/libcrypto/objects/objectstest.c +++ b/regress/lib/libcrypto/objects/objectstest.c @@ -1,4 +1,4 @@ -/* $OpenBSD: objectstest.c,v 1.6 2022/09/05 21:06:31 tb Exp $ */ +/* $OpenBSD: objectstest.c,v 1.7 2023/05/23 11:05:09 tb Exp $ */ /* * Copyright (c) 2017, 2022 Joel Sing * @@ -396,6 +396,47 @@ obj_txt_test(struct obj_test *ot) return failed; } +static int +obj_txt_early_nul_test(void) +{ + ASN1_OBJECT *obj = NULL; + char buf[2]; + int failed = 1; + + buf[0] = 'x'; + buf[1] = '\0'; + + if (OBJ_obj2txt(buf, sizeof(buf), NULL, 1) != 0) { + fprintf(stderr, "FAIL: OBJ_obj2txt(NULL) succeded\n"); + goto failed; + } + if (buf[0] != '\0') { + fprintf(stderr, "FAIL: OBJ_obj2txt(NULL) did not NUL terminate\n"); + goto failed; + } + + if ((obj = ASN1_OBJECT_new()) == NULL) + errx(1, "ASN1_OBJECT_new"); + + buf[0] = 'x'; + buf[1] = '\0'; + + if (OBJ_obj2txt(buf, sizeof(buf), obj, 1) != 0) { + fprintf(stderr, "FAIL: OBJ_obj2txt(obj) succeeded\n"); + goto failed; + } + if (buf[0] != '\0') { + fprintf(stderr, "FAIL: OBJ_obj2txt(obj) did not NUL terminate\n"); + goto failed; + } + + failed = 0; + failed: + ASN1_OBJECT_free(obj); + + return failed; +} + static int obj_txt_tests(void) { @@ -405,6 +446,8 @@ obj_txt_tests(void) for (i = 0; i < N_OBJ_TESTS; i++) failed |= obj_txt_test(&obj_tests[i]); + failed |= obj_txt_early_nul_test(); + return failed; } -- 2.20.1