From 8e7e0e23fae242cc0503b7dea8296b41df09a8f2 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 21 Jul 2025 07:41:11 -0600 Subject: [PATCH] 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. --- plugins/sudoers/timestamp.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/sudoers/timestamp.c b/plugins/sudoers/timestamp.c index 43955420f..297482b32 100644 --- a/plugins/sudoers/timestamp.c +++ b/plugins/sudoers/timestamp.c @@ -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). */ 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"); if (ftruncate(fd, old_eof) != 0) { sudo_warn(U_("unable to truncate time stamp file to %lld bytes"), (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); }