2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-09-05 00:35:14 +00:00

Properly check against errors against fwrite

fwrite is not the same as write; you have to explicitly compare against the length to detect errors, and sometimes number of items is mistaken for length.
This commit is contained in:
Rose
2025-06-17 13:44:54 -04:00
committed by Todd C. Miller
parent e6cf241b03
commit 5fad16bda2
4 changed files with 8 additions and 8 deletions

View File

@@ -68,8 +68,8 @@ sudo_printf_int(int msg_type, const char * restrict fmt, ...)
len = vasprintf(&buf, fmt, ap);
va_end(ap);
}
if (len != -1) {
if (fwrite(buf, 1, (size_t)len, ttyfp ? ttyfp : fp) == 0)
if (len >= 0) {
if (fwrite(buf, 1, (size_t)len, ttyfp ? ttyfp : fp) != (size_t)len)
len = -1;
if (buf != sbuf)
free(buf);