From: tb Date: Wed, 20 Dec 2023 14:26:47 +0000 (+0000) Subject: Use BIO_indent() for indentation in tasn_prn.c X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bd1f785c28f4b4197a47ba70a9ca93c3c4e0cc47;p=openbsd Use BIO_indent() for indentation in tasn_prn.c Using a loop to print pieces of a static buffer containing 20 spaces to indent things is just silly. Even sillier is making this buffer const without looking what it's actually used for... There is BIO_indent() or BIO_printf() that can handle "%*s". Add a length check to preserve behavior since BIO_indent() succeeds for negattive indent. However, peak silliness must be how BIO_dump_indent_cb() indents things. That's for another day. ok jsing --- diff --git a/lib/libcrypto/asn1/tasn_prn.c b/lib/libcrypto/asn1/tasn_prn.c index 3f61a689d01..d404838c68f 100644 --- a/lib/libcrypto/asn1/tasn_prn.c +++ b/lib/libcrypto/asn1/tasn_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tasn_prn.c,v 1.25 2023/07/05 21:23:36 beck Exp $ */ +/* $OpenBSD: tasn_prn.c,v 1.26 2023/12/20 14:26:47 tb Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2000. */ @@ -395,15 +395,9 @@ static int asn1_print_fsname(BIO *out, int indent, const char *fname, const char *sname, const ASN1_PCTX *pctx) { - static char spaces[] = " "; - const int nspaces = sizeof(spaces) - 1; - - while (indent > nspaces) { - if (BIO_write(out, spaces, nspaces) != nspaces) - return 0; - indent -= nspaces; - } - if (BIO_write(out, spaces, indent) != indent) + if (indent < 0) + return 0; + if (!BIO_indent(out, indent, indent)) return 0; if (pctx->flags & ASN1_PCTX_FLAGS_NO_STRUCT_NAME) sname = NULL;