Add more error checks.

This commit is contained in:
Simon Ruderich
2013-06-13 21:56:50 +02:00
parent e5a94fa847
commit f30dbbd26d
2 changed files with 4 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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",