Преглед изворни кода

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
     now need --force-architecture, dpkg will still warn about them though.
   * Fix build failure when passing --disable-nls to configure.
+  * Do not segfault on “dpkg -i --no-act”.
 
   [ Raphaël Hertzog ]
   * 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);
 
   if (f_noact) {
+    char *tmpdir;
+
     if (!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"));
+
+    cidir = cidirbuf = m_malloc(strlen(tmpdir) + MAXCONTROLFILENAME + 10);
+    strcpy(cidir, tmpdir);
     strcat(cidir,"/");
 
     cidirrest = cidir + strlen(cidir);
+
+    free(tmpdir);
   } else {
     /* We want it to be on the same filesystem so that we can
      * use rename(2) to install the postinst &c. */