From: Simon Ruderich Date: Thu, 13 Jun 2013 19:56:50 +0000 (+0200) Subject: Add more error checks. X-Git-Tag: 0.1~55 X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=commitdiff_plain;h=f30dbbd26d18e3014762ccc37b8e5ab65b596b35 Add more error checks. --- 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",