/* If the file doesn't exist, do nothing. Prevents writing log files in
* unexpected places. The user must create the file manually. */
int fd = open(DEBUG_FILE, O_WRONLY | O_APPEND);
- if (fd == -1)
+ if (fd == -1) {
return;
+ }
va_list ap;
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");