浏览代码

dpkg: Do not segfault on “dpkg -i --no-act”

mkdtemp() takes the string allocated by path_make_temp_template() and
modifies it, but there's not enough allocated room for the subsequent
string appends done starting from cidirrest, for the control files.

Regression introduced in commit ffccc65580189420a0a64736bba0fb661de56dcb.
Guillem Jover 15 年之前
父节点
当前提交
da5fceca72
共有 2 个文件被更改,包括 10 次插入2 次删除
  1. 1 0
      debian/changelog
  2. 9 2
      src/processarc.c

+ 1 - 0
debian/changelog

@@ -31,6 +31,7 @@ dpkg (1.16.0) UNRELEASED; urgency=low
   * By default reject installing packages w/o an Architecture field. They
   * By default reject installing packages w/o an Architecture field. They
     now need --force-architecture, dpkg will still warn about them though.
     now need --force-architecture, dpkg will still warn about them though.
   * Fix build failure when passing --disable-nls to configure.
   * Fix build failure when passing --disable-nls to configure.
+  * Do not segfault on “dpkg -i --no-act”.
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]
   * Fail properly when debian/source/format is empty. Closes: #600854
   * Fail properly when debian/source/format is empty. Closes: #600854

+ 9 - 2
src/processarc.c

@@ -219,14 +219,21 @@ void process_archive(const char *filename) {
     deb_verify(filename);
     deb_verify(filename);
 
 
   if (f_noact) {
   if (f_noact) {
+    char *tmpdir;
+
     if (!cidirbuf)
     if (!cidirbuf)
       free(cidirbuf);
       free(cidirbuf);
-    cidir = cidirbuf = mkdtemp(path_make_temp_template("dpkg"));
-    if (!cidir)
+    tmpdir = mkdtemp(path_make_temp_template("dpkg"));
+    if (!tmpdir)
       ohshite(_("unable to create temporary directory"));
       ohshite(_("unable to create temporary directory"));
+
+    cidir = cidirbuf = m_malloc(strlen(tmpdir) + MAXCONTROLFILENAME + 10);
+    strcpy(cidir, tmpdir);
     strcat(cidir,"/");
     strcat(cidir,"/");
 
 
     cidirrest = cidir + strlen(cidir);
     cidirrest = cidir + strlen(cidir);
+
+    free(tmpdir);
   } else {
   } else {
     /* We want it to be on the same filesystem so that we can
     /* We want it to be on the same filesystem so that we can
      * use rename(2) to install the postinst &c. */
      * use rename(2) to install the postinst &c. */