Blob Blame History Raw
diff -up ./src/copy_file.c.symbolic-link-attack-5 ./src/copy_file.c
--- ./src/copy_file.c.symbolic-link-attack-5	2021-02-02 17:18:05.355567274 +0100
+++ ./src/copy_file.c	2021-02-02 17:19:09.904671563 +0100
@@ -128,7 +128,6 @@ write_error:
     }
 }
 
-#ifdef HAVE_SELINUX
 bool
 sudo_check_temp_file(int tfd, const char *tfile, uid_t uid, struct stat *sb)
 {
@@ -158,4 +157,3 @@ sudo_check_temp_file(int tfd, const char
     }
     debug_return_bool(true);
 }
-#endif /* SELINUX */
diff -up ./src/sudo_edit.c.symbolic-link-attack-5 ./src/sudo_edit.c
--- ./src/sudo_edit.c.symbolic-link-attack-5	2021-02-02 17:18:05.355567274 +0100
+++ ./src/sudo_edit.c	2021-02-02 17:18:05.356567260 +0100
@@ -692,24 +692,17 @@ sudo_edit_copy_tfiles(struct command_det
 
     /* Copy contents of temp files to real ones. */
     for (i = 0; i < nfiles; i++) {
-	int rc = -1;
 	sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
 	    "seteuid(%u)", (unsigned int)user_details.uid);
 	if (seteuid(user_details.uid) != 0)
 	    sudo_fatal("seteuid(%u)", (unsigned int)user_details.uid);
 	tfd = sudo_edit_open(tf[i].tfile, O_RDONLY,
 	    S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, NULL);
-	if (tfd != -1)
-	    rc = fstat(tfd, &sb);
-	sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
-	    "seteuid(%u)", ROOT_UID);
 	if (seteuid(ROOT_UID) != 0)
 	    sudo_fatal("seteuid(ROOT_UID)");
-	if (rc == -1 || !S_ISREG(sb.st_mode)) {
-	    if (rc == -1)
-		sudo_warn("%s", tf[i].tfile);
-	    else
-		sudo_warnx(U_("%s: not a regular file"), tf[i].tfile);
+	sudo_debug_printf(SUDO_DEBUG_INFO|SUDO_DEBUG_LINENO,
+	    "seteuid(%u)", ROOT_UID);
+	if (tfd == -1 || !sudo_check_temp_file(tfd, tf[i].tfile, user_details.uid, &sb)) {
 	    sudo_warnx(U_("%s left unmodified"), tf[i].ofile);
 	    if (tfd != -1)
 		close(tfd);