From: tb Date: Thu, 1 Feb 2024 17:04:09 +0000 (+0000) Subject: Prepare to remove the _cb() and _fp() versions of BIO_dump() X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bd79a156a68651fd92d7f18584dd741631bce967;p=openbsd Prepare to remove the _cb() and _fp() versions of BIO_dump() apache-httpd uses BIO_dump(), libssl uses BIO_dump_indent(), and the openssl(1) app uses both. Otherwise this is unused. This is horribly bad code even by libcrypto standards. By doing away with the callbacks fixes incorrect error checking for fwrite() but there is a lot more wrong in here. This can be cleaned up in a later pass, the only concern here is to be able to remove the unused variants in the next major bump. ok beck --- diff --git a/lib/libcrypto/bio/b_dump.c b/lib/libcrypto/bio/b_dump.c index e46424e6998..ef965b61d0c 100644 --- a/lib/libcrypto/bio/b_dump.c +++ b/lib/libcrypto/bio/b_dump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: b_dump.c,v 1.26 2023/07/29 02:32:00 tb Exp $ */ +/* $OpenBSD: b_dump.c,v 1.27 2024/02/01 17:04:09 tb Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -64,21 +64,14 @@ #include #include +#include #define TRUNCATE #define DUMP_WIDTH 16 #define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH - ((i - (i > 6 ? 6 : i) + 3) / 4)) int -BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), - void *u, const char *s, int len) -{ - return BIO_dump_indent_cb(cb, u, s, len, 0); -} - -int -BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), - void *u, const char *s, int len, int indent) +BIO_dump_indent(BIO *bio, const char *s, int len, int indent) { char buf[288 + 1], tmp[20], str[128 + 1]; int i, j, rows, trc, written; @@ -132,7 +125,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), /* if this is the last call then update the ddt_dump thing so * that we will move the selection point in the debug window */ - if ((written = cb((void *)buf, strlen(buf), u)) < 0) + if ((written = BIO_write(bio, buf, strlen(buf))) < 0) return -1; ret += written; @@ -141,50 +134,54 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), if (trc > 0) { snprintf(buf, sizeof buf, "%s%04x - \n", str, len + trc); - if ((written = cb((void *)buf, strlen(buf), u)) < 0) + if ((written = BIO_write(bio, buf, strlen(buf))) < 0) return -1; ret += written; } #endif return (ret); } - -static int -write_fp(const void *data, size_t len, void *fp) -{ - return fwrite(data, 1, len, fp); -} +LCRYPTO_ALIAS(BIO_dump_indent); int -BIO_dump_fp(FILE *fp, const char *s, int len) +BIO_dump(BIO *bio, const char *s, int len) { - return BIO_dump_cb(write_fp, fp, s, len); + return BIO_dump_indent(bio, s, len, 0); } -LCRYPTO_ALIAS(BIO_dump_fp); +LCRYPTO_ALIAS(BIO_dump); + +/* + * XXX - remove the functions below in the next major bump. + */ int -BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) +BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const char *s, int len) { - return BIO_dump_indent_cb(write_fp, fp, s, len, indent); + BIOerror(ERR_R_DISABLED); + return -1; } -LCRYPTO_ALIAS(BIO_dump_indent_fp); -static int -write_bio(const void *data, size_t len, void *bp) +int +BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), + void *u, const char *s, int len, int indent) { - return BIO_write((BIO *)bp, (const char *)data, len); + BIOerror(ERR_R_DISABLED); + return -1; } int -BIO_dump(BIO *bp, const char *s, int len) +BIO_dump_fp(FILE *fp, const char *s, int len) { - return BIO_dump_cb(write_bio, bp, s, len); + BIOerror(ERR_R_DISABLED); + return -1; } -LCRYPTO_ALIAS(BIO_dump); +LCRYPTO_ALIAS(BIO_dump_fp); int -BIO_dump_indent(BIO *bp, const char *s, int len, int indent) +BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent) { - return BIO_dump_indent_cb(write_bio, bp, s, len, indent); + BIOerror(ERR_R_DISABLED); + return -1; } -LCRYPTO_ALIAS(BIO_dump_indent); +LCRYPTO_ALIAS(BIO_dump_indent_fp);