]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/commitdiff
debug.h: Handle overflow in debug().
authorSimon Ruderich <simon@ruderich.org>
Mon, 3 Jun 2013 02:32:12 +0000 (04:32 +0200)
committerSimon Ruderich <simon@ruderich.org>
Mon, 3 Jun 2013 02:32:12 +0000 (04:32 +0200)
src/debug.h

index 6456898cb7e601bb6fe987e3e4f6a39831f154cd..4dab03c3407600fad3556e498ca921ddf33a370d 100644 (file)
@@ -33,6 +33,10 @@ static void debug(const char *format, ...) {
     va_start(ap, format);
     int written = vsnprintf(buffer, sizeof(buffer), format, ap);
     va_end(ap);
+    /* Overflow. */
+    if ((size_t)written >= sizeof(buffer)) {
+        written = sizeof(buffer) - 1;
+    }
 
     /* Make sure these functions are loaded. */
     DLSYM_FUNCTION(real_write, "write");