Просмотр исходного кода

dpkg-divert: Change file_copy() and rename_mv() to ohshite() on error

This has several consequences, the code will not trigger leak detectors
like cppcheck due to ohshite() being marked non-returning, and the error
messages are going to be more descriptive.

Closes: #620380
Guillem Jover лет назад: 15
Родитель
Сommit
d1ad33f057
2 измененных файлов с 13 добавлено и 17 удалено
  1. 3 0
      debian/changelog
  2. 10 17
      src/divertcmd.c

+ 3 - 0
debian/changelog

@@ -50,6 +50,9 @@ dpkg (1.16.0) UNRELEASED; urgency=low
   * Fix undefined value useage in dpkg-genchanges when adding files w/o a
     matching architecture, because they are not present in debian/control,
     this is most commonly the case due to dpkg-distaddfile.
+  * Terminate immediately on dpkg-divert rename errors instead of propagating
+    up the error codes, this improves error reporting and avoids triggering
+    leak detectors. Closes: #620380
 
   [ Raphaël Hertzog ]
   * Fail properly when debian/source/format is empty. Closes: #600854

+ 10 - 17
src/divertcmd.c

@@ -206,18 +206,18 @@ check_rename(struct file *src, struct file *dst)
 	return true;
 }
 
-static int
+static void
 file_copy(const char *src, const char *dst)
 {
 	int srcfd, dstfd;
 
 	srcfd = open(src, O_RDONLY);
 	if (srcfd < 0)
-		return -1;
+		ohshite(_("unable to open file '%s'"), src);
 
 	dstfd = creat(dst, 0600);
 	if (dstfd < 0)
-		return -1;
+		ohshite(_("unable to create file '%s'"), dst);
 
 	/* FIXME: leaves a dangling destination file on error. */
 
@@ -226,36 +226,31 @@ file_copy(const char *src, const char *dst)
 	close(srcfd);
 
 	if (fsync(dstfd))
-		return -1;
+		ohshite(_("unable to sync file '%s'"), dst);
 	if (close(dstfd))
-		return -1;
+		ohshite(_("unable to close file '%s'"), dst);
 
 	file_copy_perms(src, dst);
-
-	return 0;
 }
 
-static int
+static void
 rename_mv(const char *src, const char *dst)
 {
 	char *tmpdst;
 
 	if (rename(src, dst) == 0)
-		return 0;
+		return;
 
 	m_asprintf(&tmpdst, "%s%s", dst, ".dpkg-divert.tmp");
 
 	/* If a simple rename didn't work try an atomic copy, rename, unlink
 	 * instead. */
-	if (file_copy(src, tmpdst) != 0)
-		return -1;
+	file_copy(src, tmpdst);
 
 	if (rename(tmpdst, dst) != 0)
-		return -1;
+		ohshite(_("cannot rename '%s' to '%s'"), tmpdst, dst);
 
 	free(tmpdst);
-
-	return 0;
 }
 
 static void
@@ -269,9 +264,7 @@ file_rename(struct file *src, struct file *dst)
 			ohshite(_("rename: remove duplicate old link '%s'"),
 			        src->name);
 	} else {
-		if (rename_mv(src->name, dst->name))
-			ohshite(_("cannot rename '%s' to '%s'"),
-			        src->name, dst->name);
+		rename_mv(src->name, dst->name);
 	}
 }