From: tb Date: Tue, 23 May 2023 11:51:12 +0000 (+0000) Subject: Simplify OBJ_obj2txt() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=fcb77b6b49ad76dea8c856e3a3a8cbc7f614d1d2;p=openbsd 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 --- diff --git a/lib/libcrypto/asn1/a_object.c b/lib/libcrypto/asn1/a_object.c index 8c8ca8537fb..af19858f74f 100644 --- a/lib/libcrypto/asn1/a_object.c +++ b/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/lib/libcrypto/objects/obj_dat.c b/lib/libcrypto/objects/obj_dat.c index fcc21ddfb42..7516a6d09a7 100644 --- a/lib/libcrypto/objects/obj_dat.c +++ b/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); }