From 1f3bd948a7a57f8afd725ff65663d7e5a9c498b0 Mon Sep 17 00:00:00 2001 From: tb Date: Wed, 10 Jan 2024 14:22:53 +0000 Subject: [PATCH] Fix print_fp() The callback-based printing needs to die. But first BIO_set() will die. We have a FILE *. We have fprintf(). No need to use a static BIO to dump error codes to said stream. This basically undoes an unrelated change of "Move crpytlib.h prior bio.h" from 19 years ago (OpenSSL 25a66ee3). Except we don't cast and check len. ok jsing (who had a nearly identical diff) --- lib/libcrypto/err/err_prn.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/libcrypto/err/err_prn.c b/lib/libcrypto/err/err_prn.c index d60cfdcb92a..16d8862a822 100644 --- a/lib/libcrypto/err/err_prn.c +++ b/lib/libcrypto/err/err_prn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: err_prn.c,v 1.20 2023/07/07 13:54:45 beck Exp $ */ +/* $OpenBSD: err_prn.c,v 1.21 2024/01/10 14:22:53 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,6 +56,7 @@ * [including the GNU Public Licence.] */ +#include #include #include @@ -93,12 +94,9 @@ LCRYPTO_ALIAS(ERR_print_errors_cb); static int print_fp(const char *str, size_t len, void *fp) { - BIO bio; - - BIO_set(&bio, BIO_s_file()); - BIO_set_fp(&bio, fp, BIO_NOCLOSE); - - return BIO_printf(&bio, "%s", str); + if (len > INT_MAX) + return -1; + return fprintf(fp, "%.*s", (int)len, str); } void -- 2.20.1