From 61503dd412d8dc1325b7f7fa2e752b925b1e8b9d Mon Sep 17 00:00:00 2001 From: beck <> Date: Sun, 11 Jul 2021 20:18:07 +0000 Subject: While the traditional OpenSSL return value and behaviour of BIO_dump(3) is pure comedy gold, and now documented as such, sadly this bit of pure Muppet genius can't really in good consience stay in the tree as is. Change BIO_dump to always return the number of bytes printed on success and to stop printing and return -1 on failure if a writing function fails. ok tb@, jsing@ --- src/lib/libcrypto/bio/b_dump.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/lib/libcrypto/bio/b_dump.c') diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c index 0214addc8b..7e1c2d7947 100644 --- a/src/lib/libcrypto/bio/b_dump.c +++ b/src/lib/libcrypto/bio/b_dump.c @@ -1,10 +1,10 @@ -/* $OpenBSD: b_dump.c,v 1.21 2015/04/23 06:11:19 deraadt Exp $ */ +/* $OpenBSD: b_dump.c,v 1.22 2021/07/11 20:18:07 beck Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. +* The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions @@ -82,7 +82,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), { int ret = 0; char buf[288 + 1], tmp[20], str[128 + 1]; - int i, j, rows, trc; + int i, j, rows, trc, written; unsigned char ch; int dump_width; @@ -133,13 +133,18 @@ 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 */ - ret += cb((void *)buf, strlen(buf), u); + if ((written = cb((void *)buf, strlen(buf), u)) < 0) + return -1; + ret += written; + } #ifdef TRUNCATE if (trc > 0) { snprintf(buf, sizeof buf, "%s%04x - \n", str, len + trc); - ret += cb((void *)buf, strlen(buf), u); + if ((written = cb((void *)buf, strlen(buf), u)) < 0) + return -1; + ret += written; } #endif return (ret); -- cgit v1.2.3-55-g6feb