summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2021-03-25 09:26:17 +0000
committertb <>2021-03-25 09:26:17 +0000
commitddc7b9ae1f6946ef630d88aa97eddbf7fb325186 (patch)
tree0bf54ef8e5b07756f58d58dd170e71324212ef23 /src
parent78304416451899bb48e1cb86c96eafb6fa3cbaf3 (diff)
downloadopenbsd-ddc7b9ae1f6946ef630d88aa97eddbf7fb325186.tar.gz
openbsd-ddc7b9ae1f6946ef630d88aa97eddbf7fb325186.tar.bz2
openbsd-ddc7b9ae1f6946ef630d88aa97eddbf7fb325186.zip
Avoid mangled output in BIO_debug_callback
Instead of blindly skipping 14 characters, we can use the return value of snprintf() to determine how much we should skip. From Martin Vahlensieck with minor tweaks by me
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/bio/bio_cb.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/lib/libcrypto/bio/bio_cb.c b/src/lib/libcrypto/bio/bio_cb.c
index ab0e3a92ce..52cdd24177 100644
--- a/src/lib/libcrypto/bio/bio_cb.c
+++ b/src/lib/libcrypto/bio/bio_cb.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bio_cb.c,v 1.16 2014/12/08 03:54:19 bcook Exp $ */ 1/* $OpenBSD: bio_cb.c,v 1.17 2021/03/25 09:26:17 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -70,15 +70,22 @@ BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl,
70 BIO *b; 70 BIO *b;
71 char buf[256]; 71 char buf[256];
72 char *p; 72 char *p;
73 int nbuf;
73 long r = 1; 74 long r = 1;
74 size_t p_maxlen; 75 size_t p_maxlen;
75 76
76 if (BIO_CB_RETURN & cmd) 77 if (BIO_CB_RETURN & cmd)
77 r = ret; 78 r = ret;
78 79
79 snprintf(buf, sizeof buf, "BIO[%p]:", bio); 80 nbuf = snprintf(buf, sizeof(buf), "BIO[%p]: ", bio);
80 p = &(buf[14]); 81 if (nbuf < 0)
81 p_maxlen = sizeof buf - 14; 82 nbuf = 0; /* Ignore error; continue printing. */
83 if (nbuf >= sizeof(buf))
84 goto out;
85
86 p = buf + nbuf;
87 p_maxlen = sizeof(buf) - nbuf;
88
82 switch (cmd) { 89 switch (cmd) {
83 case BIO_CB_FREE: 90 case BIO_CB_FREE:
84 snprintf(p, p_maxlen, "Free - %s\n", bio->method->name); 91 snprintf(p, p_maxlen, "Free - %s\n", bio->method->name);
@@ -136,6 +143,7 @@ BIO_debug_callback(BIO *bio, int cmd, const char *argp, int argi, long argl,
136 break; 143 break;
137 } 144 }
138 145
146 out:
139 b = (BIO *)bio->cb_arg; 147 b = (BIO *)bio->cb_arg;
140 if (b != NULL) 148 if (b != NULL)
141 BIO_write(b, buf, strlen(buf)); 149 BIO_write(b, buf, strlen(buf));