ソースを参照

dpkg: Always return from ensure_statoverrides() if file is NULL

Do not proceed within the function if we cannot open the current
database because it does not exist and we opened it before. This
will only get us to read garbage from memory or segfault.

Warned-by: clang static analyzer
Guillem Jover 12 年 前
コミット
1d5471c21a
共有2 個のファイルを変更した7 個の追加0 個の削除を含む
  1. 2 0
      debian/changelog
  2. 5 0
      src/statdb.c

+ 2 - 0
debian/changelog

@@ -77,6 +77,8 @@ dpkg (1.17.2) UNRELEASED; urgency=low
     documentation and code comments.
   * Do not NULL-terminate the list in the compat scandir(), as this might
     cause a segfault in case the function returns 0 entries.
+  * Always return from ensure_statoverrides() if file is NULL, otherwise
+    we might get us to read garbage from memory or segfault.
 
   [ Updated programs translations ]
   * German (Sven Joachim).

+ 5 - 0
src/statdb.c

@@ -150,6 +150,11 @@ ensure_statoverrides(void)
 	statoverridefile = file;
 	setcloexec(fileno(statoverridefile), statoverridename);
 
+	if (!file) {
+		onerr_abort--;
+		return;
+	}
+
 	/* If the statoverride list is empty we don't need to bother
 	 * reading it. */
 	if (!sb_next.st_size) {