Kaynağa Gözat

Few file descriptor cleanup and error handling fixes

Closes: #443338
Ian Jackson 18 yıl önce
ebeveyn
işleme
48ed165728
5 değiştirilmiş dosya ile 21 ekleme ve 7 silme
  1. 10 0
      ChangeLog
  2. 2 0
      debian/changelog
  3. 3 3
      lib/parse.c
  4. 2 1
      src/archives.c
  5. 4 3
      src/processarc.c

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2008-03-21  Ian Jackson  <ian@davenant.greenend.org.uk>
+
+	* src/archives.c (tarobject): Make 'fd' static.
+	* lib/parse.c (parsedb): Likewise. Use ehflag_normaltidy on
+	push_cleanup and pop_cleanup. Move pop_cleanup call just before its
+	related close call.
+	* src/processarc.c (process_archive): Do not install two cleanup
+	handlers to close the fsys-tarfile pipe. Mark pipe descriptors with
+	invalid values when closed.
+
 2008-03-20  Guillem Jover  <guillem@debian.org>
 
 	* dpkg-deb/extract.c (safe_fflush): Change return type from int to

+ 2 - 0
debian/changelog

@@ -29,6 +29,8 @@ dpkg (1.14.17) UNRELEASED; urgency=low
     a non glibc claims to be glibc. Closes: #465420
   * Fix crash when a .deb file becomes unreadable while dpkg is starting.
     Thanks to Ian Jackson. Closes: #386210
+  * Few file descriptor cleanup and error handling fixes.
+    Thanks to Ian Jackson. Closes: #443338
 
   [ Raphael Hertzog ]
   * Add a warning displayed by dpkg-genchanges if the current version is

+ 3 - 3
lib/parse.c

@@ -84,7 +84,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
    * If donep is not null only one package's information is expected.
    */
   
-  int fd;
+  static int fd;
   struct pkginfo newpig, *pigp;
   struct pkginfoperfile *newpifp, *pifp;
   struct arbitraryfield *arp, **larpp;
@@ -105,7 +105,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
   fd= open(filename, O_RDONLY);
   if (fd == -1) ohshite(_("failed to open package info file `%.255s' for reading"),filename);
 
-  push_cleanup(cu_parsedb,~0, NULL,0, 1,&fd);
+  push_cleanup(cu_parsedb, ~ehflag_normaltidy, NULL, 0, 1, &fd);
 
   if (fstat(fd, &stat) == -1)
     ohshite(_("can't stat package info file `%.255s'"),filename);
@@ -318,7 +318,6 @@ int parsedb(const char *filename, enum parsedbflags flags,
     if (EOF_mmap(dataptr, endptr)) break;
     if (c == '\n') lno++;
   }
-  pop_cleanup(0);
   if (data != NULL) {
 #ifdef HAVE_MMAP
     munmap(data, stat.st_size);
@@ -327,6 +326,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
 #endif
   }
   free(value);
+  pop_cleanup(ehflag_normaltidy);
   if (close(fd)) ohshite(_("failed to close after read: `%.255s'"),filename);
   if (donep && !pdone) ohshit(_("no package information in `%.255s'"),filename);
 

+ 2 - 1
src/archives.c

@@ -371,11 +371,12 @@ static int linktosameexistingdir(const struct TarInfo *ti,
 
 int tarobject(struct TarInfo *ti) {
   static struct varbuf conffderefn, hardlinkfn, symlinkfn;
+  static int fd;
   const char *usename;
 
   struct conffile *conff;
   struct tarcontext *tc= (struct tarcontext*)ti->UserData;
-  int statr, fd, i, existingdirectory, keepexisting;
+  int statr, i, existingdirectory, keepexisting;
   ssize_t r;
   struct stat stab, stabtmp;
   char databuf[TARBLKSZ];

+ 4 - 3
src/processarc.c

@@ -561,13 +561,13 @@ void process_archive(const char *filename) {
     ohshite(_("unable to exec dpkg-deb to get filesystem archive"));
   }
   close(p1[1]);
+  p1[1] = -1;
 
   newfileslist = NULL;
   tc.newfilesp = &newfileslist;
   push_cleanup(cu_fileslist, ~0, NULL, 0, 0);
   tc.pkg= pkg;
   tc.backendpipe= p1[0];
-  push_cleanup(cu_closefd, ~ehflag_bombout, NULL, 0, 1, &tc.backendpipe);
 
   r= TarExtractor((void*)&tc, &tf);
   if (r) {
@@ -577,8 +577,9 @@ void process_archive(const char *filename) {
       ohshit(_("corrupted filesystem tarfile - corrupted package archive"));
     }
   }
-  fd_null_copy(tc.backendpipe,-1,_("dpkg-deb: zap possible trailing zeros"));
-  close(tc.backendpipe);
+  fd_null_copy(p1[0], -1, _("dpkg-deb: zap possible trailing zeros"));
+  close(p1[0]);
+  p1[0] = -1;
   waitsubproc(c1,BACKEND " --fsys-tarfile",PROCPIPE);
 
   if (oldversionstatus == stat_halfinstalled || oldversionstatus == stat_unpacked) {