Skip to content

Commit 8e7e0e2

Browse files
committed
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.
1 parent fac2a49 commit 8e7e0e2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

plugins/sudoers/timestamp.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,17 @@ ts_write(const struct sudoers_context *ctx, int fd, const char *fname,
358358

359359
/* Truncate on partial write to be safe (assumes end of file). */
360360
if (nwritten > 0) {
361-
sudo_debug_printf(SUDO_DEBUG_DEBUG|SUDO_DEBUG_LINENO,
361+
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
362362
"short write, truncating partial time stamp record");
363363
if (ftruncate(fd, old_eof) != 0) {
364364
sudo_warn(U_("unable to truncate time stamp file to %lld bytes"),
365365
(long long)old_eof);
366366
}
367+
if (lseek(fd, old_eof, SEEK_SET) == -1) {
368+
sudo_debug_printf(
369+
SUDO_DEBUG_ERROR|SUDO_DEBUG_ERRNO|SUDO_DEBUG_LINENO,
370+
"unable to seek to %lld", (long long)old_eof);
371+
}
367372
}
368373
debug_return_ssize_t(-1);
369374
}

0 commit comments

Comments
 (0)