2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-22 18:08:23 +00:00

ts_write: call lseek after fruncate on short write

We need to make sure the file position is reset to the old EOF on
error.
This commit is contained in:
Todd C. Miller 2025-07-21 07:41:11 -06:00
parent fac2a49e75
commit 8e7e0e23fa

View File

@ -358,12 +358,17 @@ ts_write(const struct sudoers_context *ctx, int fd, const char *fname,
/* Truncate on partial write to be safe (assumes end of file). */ /* Truncate on partial write to be safe (assumes end of file). */
if (nwritten > 0) { if (nwritten > 0) {
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO, sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
"short write, truncating partial time stamp record"); "short write, truncating partial time stamp record");
if (ftruncate(fd, old_eof) != 0) { if (ftruncate(fd, old_eof) != 0) {
sudo_warn(U_("unable to truncate time stamp file to %lld bytes"), sudo_warn(U_("unable to truncate time stamp file to %lld bytes"),
(long long)old_eof); (long long)old_eof);
} }
if (lseek(fd, old_eof, SEEK_SET) == -1) {
sudo_debug_printf(
SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
"unable to seek to %lld", (long long)old_eof);
}
} }
debug_return_ssize_t(-1); debug_return_ssize_t(-1);
} }