From 7cab7499f764c06376e465d4c8264bd7315c181c Mon Sep 17 00:00:00 2001 From: tb <> Date: Tue, 23 May 2023 11:51:12 +0000 Subject: Simplify OBJ_obj2txt() Instead of adding a NUL termination to OBJ_obj2txt(), move the aobj == NULL or aobj->data == NULL checks to i2t_ASN1_OBJECT_internal(). The only other caller, i2t_ASN1_OBJECT(), fails on aobj == NULL and aobj->length == 0, and the latter condition is implied by aobj->data. Cleaner solution for obj_dat.c r1.52 suggested by/ok jsing --- src/lib/libcrypto/asn1/a_object.c | 5 ++++- src/lib/libcrypto/objects/obj_dat.c | 8 +------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 8c8ca8537f..af19858f74 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c @@ -1,4 +1,4 @@ -/* $OpenBSD: a_object.c,v 1.49 2022/11/26 16:08:50 tb Exp $ */ +/* $OpenBSD: a_object.c,v 1.50 2023/05/23 11:51:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -433,6 +433,9 @@ i2t_ASN1_OBJECT_internal(const ASN1_OBJECT *aobj, char *buf, int buf_len, int no if (buf_len > 0) buf[0] = '\0'; + if (aobj == NULL || aobj->data == NULL) + return 0; + if (!CBB_init(&cbb, 0)) goto err; if (!i2t_ASN1_OBJECT_cbb(aobj, &cbb, no_name)) diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index fcc21ddfb4..7516a6d09a 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: obj_dat.c,v 1.52 2023/05/23 11:04:04 tb Exp $ */ +/* $OpenBSD: obj_dat.c,v 1.53 2023/05/23 11:51:12 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -499,12 +499,6 @@ OBJ_txt2obj(const char *s, int no_name) int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *aobj, int no_name) { - if (buf_len > 0) - buf[0] = '\0'; - - if (aobj == NULL || aobj->data == NULL) - return 0; - return i2t_ASN1_OBJECT_internal(aobj, buf, buf_len, no_name); } -- cgit v1.2.3-55-g6feb