From 669add756e0287038c68083d57b12275b80e87d5 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Fri, 7 Jun 2019 17:04:41 +0100 Subject: [PATCH] Convert dump_buf_hex() to use oc_text_buf instead of sprintf I seem to recall the OpenBSD build will complain loudly about the use of "bad" functions like sprintf. And even though this particular code does seem to be perfectly correct, they do have a point in the general case. Just use buf_append() for this, since that's what it was designed for. Signed-off-by: David Woodhouse --- http.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/http.c b/http.c index 243553e0..43499505 100644 --- a/http.c +++ b/http.c @@ -797,23 +797,30 @@ void dump_buf(struct openconnect_info *vpninfo, char prefix, char *buf) void dump_buf_hex(struct openconnect_info *vpninfo, int loglevel, char prefix, unsigned char *buf, int len) { - char linebuf[80]; + struct oc_text_buf *line = buf_alloc(); int i, j; for (i = 0; i < len; i+=16) { - sprintf(linebuf, "%04x:", i); + buf_truncate(line); + buf_append(line, "%04x:", i); for (j = i; j < i+16; j++) { + if (!(j & 7)) + buf_append(line, " "); + if (j < len) - sprintf(linebuf + strlen(linebuf), " %02x", buf[j]); + buf_append(line, " %02x", buf[j]); else - sprintf(linebuf + strlen(linebuf), " "); + buf_append(line, " "); } - sprintf(linebuf + strlen(linebuf), " |"); + buf_append(line, " |"); for (j = i; j < i+16 && j < len; j++) - sprintf(linebuf + strlen(linebuf), "%c", isprint(buf[j]) || buf[j]==' ' ? buf[j] : '.'); - sprintf(linebuf + strlen(linebuf), "|"); - vpn_progress(vpninfo, loglevel, "%c %s\n", prefix, linebuf); + buf_append(line, "%c", isprint(buf[j])? buf[j] : '.'); + buf_append(line, "|"); + if (buf_error(line)) + break; + vpn_progress(vpninfo, loglevel, "%c %s\n", prefix, line->data); } + buf_free(line); } /* Inputs: -- 2.49.0