The following commit has been merged in the master branch:
commit f7c561fe071e2e7d90de2af262cd0c648e172590
Author: Guillem Jover <[EMAIL PROTECTED]>
Date:   Tue Jul 1 04:44:12 2008 +0300

    dpkg: Do not allocate memory when lstat fails while upgrading

diff --git a/ChangeLog b/ChangeLog
index 15f57b7..be02b23 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-07-01  Guillem Jover  <[EMAIL PROTECTED]>
+
+       * src/processarc.c (process_archive): Do not allocate a struct stat
+       when lstat fails, instead assign a pointer to a static empty stat
+       variable that will mark it as such.
+
 2008-06-30  Guillem Jover  <[EMAIL PROTECTED]>
 
        * lib/showpkg.c (parsefield): Remove unneeded 'const char *' cast.
diff --git a/debian/changelog b/debian/changelog
index 04a46a9..bfbd6a0 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -22,6 +22,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Support diverting files when origin and destination are on different file
     systems. Based on a patch by Juergen Kreileder. Closes: #102144, #149961
   * Do not silently enable --rename on dpkg-divert --remove. Closes: #160848
+  * Do not allocate memory when lstat fails during package upgrade.
 
   [ Raphael Hertzog ]
   * Enhance dpkg-shlibdeps's error message when a library can't be found to
diff --git a/src/processarc.c b/src/processarc.c
index 667ca7b..75535d0 100644
--- a/src/processarc.c
+++ b/src/processarc.c
@@ -680,6 +680,8 @@ void process_archive(const char *filename) {
        * since ones that stayed the same don't really apply here.
        */
       struct fileinlist *sameas = NULL;
+      static struct stat empty_stat;
+
       /* If we can't stat the old or new file, or it's a directory,
        * we leave it up to the normal code
        */
@@ -688,17 +690,21 @@ void process_archive(const char *filename) {
 
       for (cfile= newfileslist; cfile; cfile= cfile->next) {
        if (!cfile->namenode->filestat) {
-         cfile->namenode->filestat= nfmalloc(sizeof(struct stat));
-         if (lstat(cfile->namenode->name, cfile->namenode->filestat)) {
+         struct stat tmp_stat;
+
+         if (lstat(cfile->namenode->name, &tmp_stat) == 0) {
+           cfile->namenode->filestat = nfmalloc(sizeof(struct stat));
+           memcpy(cfile->namenode->filestat, &tmp_stat, sizeof(struct stat));
+         } else {
            if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
              ohshite(_("unable to stat other new file `%.250s'"),
                      cfile->namenode->name);
-           memset(cfile->namenode->filestat, 0,
-                  sizeof(*cfile->namenode->filestat));
+           cfile->namenode->filestat = &empty_stat;
            continue;
          }
        }
-       if (!cfile->namenode->filestat->st_mode) continue;
+       if (cfile->namenode->filestat == &empty_stat)
+         continue;
        if (oldfs.st_dev == cfile->namenode->filestat->st_dev &&
            oldfs.st_ino == cfile->namenode->filestat->st_ino) {
          if (sameas)

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to