From f30dbbd26d18e3014762ccc37b8e5ab65b596b35 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Thu, 13 Jun 2013 21:56:50 +0200 Subject: [PATCH] Add more error checks. --- src/debug.h | 4 +++- src/trackfds.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/debug.h b/src/debug.h index 4a7c00b..5e5cc6d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -24,8 +24,10 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap) char buffer[1024]; int written = vsnprintf(buffer, sizeof(buffer), format, ap); + if (written < 0) { + return; /* shouldn't happen */ /* Overflow. */ - if ((size_t)written >= sizeof(buffer)) { + } else if ((size_t)written >= sizeof(buffer)) { written = sizeof(buffer) - 1; } diff --git a/src/trackfds.h b/src/trackfds.h index ed2ea57..00b3b6e 100644 --- a/src/trackfds.h +++ b/src/trackfds.h @@ -169,7 +169,7 @@ static char *update_environment_buffer_entry(char *x, int fd) { assert(fd >= 0); int length = snprintf(x, 10 + 1, "%d", fd); - if (length >= 10 + 1) { + if (length >= 10 + 1 || length <= 0 /* shouldn't happen */) { /* Integer too big to fit the buffer, skip it. */ #ifdef WARNING warning("update_environment_buffer_entry(): truncated fd: %d [%d]\n", -- 2.45.2