Procházet zdrojové kódy

u-a: Fix TOCTOU race in rename_mv()

This does not have any security implications, but it makes the code
more robust.

Warned-by: coverity
Guillem Jover před 12 roky
rodič
revize
96d58c8191
2 změnil soubory, kde provedl 10 přidání a 13 odebrání
  1. 1 0
      debian/changelog
  2. 9 13
      utils/update-alternatives.c

+ 1 - 0
debian/changelog

@@ -13,6 +13,7 @@ dpkg (1.17.10) UNRELEASED; urgency=low
   * Fix non-security sensitive TOCTOU race in triggers database loading.
   * Fix non-security sensitive TOCTOU race in update-alternative alternative
     database loading.
+  * Fix non-security sensitive TOCTOU race in update-alternative rename code.
 
   [ Updated manpages translations ]
   * German (Helge Kreutzmann).

+ 9 - 13
utils/update-alternatives.c

@@ -459,23 +459,19 @@ subcall(const char *prog, ...)
 static bool
 rename_mv(const char *src, const char *dst)
 {
-	struct stat st;
+	const char *args[] = { "mv", src, dst, NULL };
+	int rc;
 
-	if (lstat(src, &st) != 0)
+	if (rename(src, dst) == 0)
+		return true;
+	if (errno == ENOENT)
 		return false;
 
-	if (rename(src, dst) != 0) {
-		const char *args[] = { "mv", src, dst, NULL };
-		int rc;
-
-		rc = spawn("mv", args);
-		if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0)
-			return true;
-
-		return false;
-	}
+	rc = spawn("mv", args);
+	if (WIFEXITED(rc) && WEXITSTATUS(rc) == 0)
+		return true;
 
-	return true;
+	return false;
 }
 
 static void