mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Add more error checks.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user