diff --git a/doc/sudo.man.in b/doc/sudo.man.in index fcefabdd4..bcc1a7f70 100644 --- a/doc/sudo.man.in +++ b/doc/sudo.man.in @@ -25,7 +25,7 @@ .nr BA @BAMAN@ .nr LC @LCMAN@ .nr PS @PSMAN@ -.TH "SUDO" "@mansectsu@" "May 7, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" +.TH "SUDO" "@mansectsu@" "July 22, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual" .nh .if n .ad l .SH "NAME" @@ -354,6 +354,8 @@ If the specified file does not exist, it will be created. Note that unlike most commands run by \fIsudo\fR, the editor is run with the invoking user's environment unmodified. +If the temporary file becomes empty after editing, the user will +be prompted before it is installed. If, for some reason, \fBsudo\fR is unable to update a file with its edited version, the user will diff --git a/doc/sudo.mdoc.in b/doc/sudo.mdoc.in index 57295bb27..0f452420a 100644 --- a/doc/sudo.mdoc.in +++ b/doc/sudo.mdoc.in @@ -24,7 +24,7 @@ .nr BA @BAMAN@ .nr LC @LCMAN@ .nr PS @PSMAN@ -.Dd May 7, 2020 +.Dd July 22, 2020 .Dt SUDO @mansectsu@ .Os Sudo @PACKAGE_VERSION@ .Sh NAME @@ -336,6 +336,8 @@ If the specified file does not exist, it will be created. Note that unlike most commands run by .Em sudo , the editor is run with the invoking user's environment unmodified. +If the temporary file becomes empty after editing, the user will +be prompted before it is installed. If, for some reason, .Nm is unable to update a file with its edited version, the user will diff --git a/src/copy_file.c b/src/copy_file.c index 0db52630f..9aeb1f92a 100644 --- a/src/copy_file.c +++ b/src/copy_file.c @@ -86,6 +86,17 @@ sudo_copy_file(const char *src, int src_fd, off_t src_len, const char *dst, ssize_t nwritten, nread; debug_decl(sudo_copy_file, SUDO_DEBUG_UTIL); + /* Prompt the user before zeroing out an existing file. */ + if (dst_len > 0 && src_len == 0) { + fprintf(stderr, U_("%s: truncate %s to zero bytes? (y/n) [n] "), + getprogname(), dst); + if (fgets(buf, sizeof(buf), stdin) == NULL || + (buf[0] != 'y' && buf[0] != 'Y')) { + sudo_warnx(U_("not overwriting %s"), dst); + debug_return_int(0); + } + } + /* Extend the file to the new size if larger before copying. */ if (dst_len > 0 && src_len > dst_len) { if (sudo_extend_file(dst_fd, dst, src_len) == -1)