From: David Woodhouse Date: Fri, 7 Jun 2019 16:04:41 +0000 (+0100) Subject: Convert dump_buf_hex() to use oc_text_buf instead of sprintf X-Git-Tag: v8.04~53 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=669add756e0287038c68083d57b12275b80e87d5;p=users%2Fdwmw2%2Fopenconnect.git 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 --- 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: