1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

Add regress coverage for obj_dat.c r1.52

This commit is contained in:
tb 2023-05-23 11:05:09 +00:00
parent 04bfea2a9c
commit 6183aea1d1

View File

@ -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 <jsing@openbsd.org>
*
@ -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;
}