From: florian Date: Sun, 28 Apr 2024 08:29:56 +0000 (+0000) Subject: Don't filter dangerous characters by hand when strvisx(3) is right there. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=b98581f594cd35548a9576c7d095f3b649e08d8b;p=openbsd Don't filter dangerous characters by hand when strvisx(3) is right there. segfault reported by sthen, which was most likely caused by buf_dump(). OK tb --- diff --git a/usr.sbin/acme-client/netproc.c b/usr.sbin/acme-client/netproc.c index cd1b8716ca7..e2c399a22f1 100644 --- a/usr.sbin/acme-client/netproc.c +++ b/usr.sbin/acme-client/netproc.c @@ -1,4 +1,4 @@ -/* $Id: netproc.c,v 1.33 2022/12/14 18:32:26 florian Exp $ */ +/* $Id: netproc.c,v 1.34 2024/04/28 08:29:56 florian Exp $ */ /* * Copyright (c) 2016 Kristaps Dzonsons * @@ -54,34 +54,19 @@ struct conn { /* * If something goes wrong (or we're tracing output), we dump the * current transfer's data as a debug message. - * Make sure that print all non-printable characters as question marks - * so that we don't spam the console. - * Also, consolidate white-space. - * This of course will ruin string literals, but the intent here is just - * to show the message, not to replicate it. */ static void buf_dump(const struct buf *buf) { - size_t i; - int j; char *nbuf; if (buf->sz == 0) return; - if ((nbuf = malloc(buf->sz)) == NULL) - err(EXIT_FAILURE, "malloc"); - - for (j = 0, i = 0; i < buf->sz; i++) - if (isspace((unsigned char)buf->buf[i])) { - nbuf[j++] = ' '; - while (isspace((unsigned char)buf->buf[i])) - i++; - i--; - } else - nbuf[j++] = isprint((unsigned char)buf->buf[i]) ? - buf->buf[i] : '?'; - dodbg("transfer buffer: [%.*s] (%zu bytes)", j, nbuf, buf->sz); + /* must be at least 4 * srclen + 1 long */ + if ((nbuf = calloc(buf->sz + 1, 4)) == NULL) + err(EXIT_FAILURE, "calloc"); + strvisx(nbuf, buf->buf, buf->sz, VIS_SAFE); + dodbg("transfer buffer: [%s] (%zu bytes)", nbuf, buf->sz); free(nbuf); }