Przeglądaj źródła

dpkg: Do not allocate memory when lstat fails while upgrading

Guillem Jover 18 lat temu
rodzic
commit
f7c561fe07
3 zmienionych plików z 18 dodań i 5 usunięć
  1. 6 0
      ChangeLog
  2. 1 0
      debian/changelog
  3. 11 5
      src/processarc.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+2008-07-01  Guillem Jover  <guillem@debian.org>
+
+	* 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  <guillem@debian.org>
 2008-06-30  Guillem Jover  <guillem@debian.org>
 
 
 	* lib/showpkg.c (parsefield): Remove unneeded 'const char *' cast.
 	* lib/showpkg.c (parsefield): Remove unneeded 'const char *' cast.

+ 1 - 0
debian/changelog

@@ -22,6 +22,7 @@ dpkg (1.15.0) UNRELEASED; urgency=low
   * Support diverting files when origin and destination are on different file
   * Support diverting files when origin and destination are on different file
     systems. Based on a patch by Juergen Kreileder. Closes: #102144, #149961
     systems. Based on a patch by Juergen Kreileder. Closes: #102144, #149961
   * Do not silently enable --rename on dpkg-divert --remove. Closes: #160848
   * Do not silently enable --rename on dpkg-divert --remove. Closes: #160848
+  * Do not allocate memory when lstat fails during package upgrade.
 
 
   [ Raphael Hertzog ]
   [ Raphael Hertzog ]
   * Enhance dpkg-shlibdeps's error message when a library can't be found to
   * Enhance dpkg-shlibdeps's error message when a library can't be found to

+ 11 - 5
src/processarc.c

@@ -680,6 +680,8 @@ void process_archive(const char *filename) {
        * since ones that stayed the same don't really apply here.
        * since ones that stayed the same don't really apply here.
        */
        */
       struct fileinlist *sameas = NULL;
       struct fileinlist *sameas = NULL;
+      static struct stat empty_stat;
+
       /* If we can't stat the old or new file, or it's a directory,
       /* If we can't stat the old or new file, or it's a directory,
        * we leave it up to the normal code
        * 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) {
       for (cfile= newfileslist; cfile; cfile= cfile->next) {
 	if (!cfile->namenode->filestat) {
 	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))
 	    if (!(errno == ENOENT || errno == ELOOP || errno == ENOTDIR))
 	      ohshite(_("unable to stat other new file `%.250s'"),
 	      ohshite(_("unable to stat other new file `%.250s'"),
 		      cfile->namenode->name);
 		      cfile->namenode->name);
-	    memset(cfile->namenode->filestat, 0,
-		   sizeof(*cfile->namenode->filestat));
+	    cfile->namenode->filestat = &empty_stat;
 	    continue;
 	    continue;
 	  }
 	  }
 	}
 	}
-	if (!cfile->namenode->filestat->st_mode) continue;
+	if (cfile->namenode->filestat == &empty_stat)
+	  continue;
 	if (oldfs.st_dev == cfile->namenode->filestat->st_dev &&
 	if (oldfs.st_dev == cfile->namenode->filestat->st_dev &&
 	    oldfs.st_ino == cfile->namenode->filestat->st_ino) {
 	    oldfs.st_ino == cfile->namenode->filestat->st_ino) {
 	  if (sameas)
 	  if (sameas)