浏览代码

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) {