eBPF-based security platform
treewide: format from a va_list with vstrsprintf()
Daniel Borkmannb6f85d7a9268
diff --git a/Makefile.shirudo b/Makefile.shirudoindex 494b83e8..f2a1d660 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -721,7 +721,7 @@ testing/helper/test-signed-load: testing/helper/test-signed-load.c-o $@ $^ -lcryptotesting/helper/test-kernel-abi: testing/helper/test-kernel-abi.c util/kernel_abi.o \- $(LIBBPF_A)+ util/string.o $(LIBBPF_A)@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(LIBELF_LIBS) $(ZLIB_LIBS)@@ -761,7 +761,7 @@ testing/helper/test-upatch-decode: testing/helper/test-upatch-decode.c \$(Q)$(CC) $(CFLAGS) -o $@ $^ $(DYNAMIC_LIBS)testing/helper/test-exec-churn: testing/helper/test-exec-churn.c util/io.o util/malloc.o \- util/log.o+ util/log.o util/string.o@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^diff --git a/util/attest.c b/util/attest.cindex 8bfa0809..c2815538 100644--- a/util/attest.c+++ b/util/attest.c@@ -604,11 +604,10 @@ static void say(struct reporter *r, bool ok, const char *fmt, ...)if (n > 0)r->len += (size_t)n;va_start(ap, fmt);- n = vsnprintf(r->buf + r->len, r->cap - r->len, fmt, ap);+ n = vstrsprintf(r->buf + r->len, r->cap - r->len, fmt, ap);va_end(ap);if (n > 0)- r->len += (size_t)n < r->cap - r->len ? (size_t)n :- r->cap - r->len - 1;+ r->len += (size_t)n;if (r->len + 1 < r->cap) {r->buf[r->len++] = '\n';r->buf[r->len] = '\0';@@ -629,11 +628,10 @@ static void note(struct reporter *r, const char *fmt, ...)if (n > 0)r->len += (size_t)n;va_start(ap, fmt);- n = vsnprintf(r->buf + r->len, r->cap - r->len, fmt, ap);+ n = vstrsprintf(r->buf + r->len, r->cap - r->len, fmt, ap);va_end(ap);if (n > 0)- r->len += (size_t)n < r->cap - r->len ? (size_t)n :- r->cap - r->len - 1;+ r->len += (size_t)n;if (r->len + 1 < r->cap) {r->buf[r->len++] = '\n';r->buf[r->len] = '\0';diff --git a/util/kernel_abi.c b/util/kernel_abi.cindex de669f39..bb8f8f82 100644--- a/util/kernel_abi.c+++ b/util/kernel_abi.c@@ -21,6 +21,7 @@#include <bpf/libbpf.h>#include <shirudo/misc.h>+#include <shirudo/string.h>#include "kernel_abi.h"@@ -33,7 +34,8 @@ static int abi_fail(char *detail, size_t detail_sz, const char *fmt, ...)if (detail && detail_sz) {va_start(ap, fmt);- vsnprintf(detail, detail_sz, fmt, ap);+ if (vstrsprintf(detail, detail_sz, fmt, ap) < 0)+ strscpy(detail, "?", detail_sz);va_end(ap);}return -EOPNOTSUPP;diff --git a/util/log.c b/util/log.cindex 6edaea16..f8cd51d1 100644--- a/util/log.c+++ b/util/log.c@@ -10,6 +10,7 @@#include <syslog.h>#include <shirudo/misc.h>+#include <shirudo/string.h>#include "log.h"@@ -52,7 +53,8 @@ static void emit(int priority, const char *fmt, va_list ap){char msg[LOG_MSG_MAX], out[4 * LOG_MSG_MAX + 1];- vsnprintf(msg, sizeof(msg), fmt, ap);+ if (vstrsprintf(msg, sizeof(msg), fmt, ap) < 0)+ strscpy(msg, fmt, sizeof(msg));escape(out, sizeof(out), msg);syslog(priority, "%s", out);fprintf(stderr, "%s\n", out);diff --git a/util/preflight.c b/util/preflight.cindex e04b69d6..7e3678e7 100644--- a/util/preflight.c+++ b/util/preflight.c@@ -66,7 +66,8 @@ static void fail(struct shirudo_preflight_result *r,c->ok = false;va_start(ap, fmt);- vsnprintf(c->detail, sizeof(c->detail), fmt, ap);+ if (vstrsprintf(c->detail, sizeof(c->detail), fmt, ap) < 0)+ strscpy(c->detail, "?", sizeof(c->detail));va_end(ap);r->n_failed++;}