]> err.no Git - dpkg/commitdiff
Few file descriptor cleanup and error handling fixes
authorIan Jackson <ian@davenant.greenend.org.uk>
Fri, 21 Mar 2008 19:46:58 +0000 (21:46 +0200)
committerGuillem Jover <guillem@debian.org>
Sat, 22 Mar 2008 04:08:51 +0000 (06:08 +0200)
Closes: #443338
ChangeLog
debian/changelog
lib/parse.c
src/archives.c
src/processarc.c

index b68e4d006a237d49b56fdd86a1ae25c9de75ce49..87c50284ca397518d48926b4b9b906c15648f1c6 100644 (file)
--- a/ChangeLog
+++ b/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
index ffd82402b631cfdf8bf237044310890acb73ef1e..22a4cf0704e5951163d1a09c460d905972be36be 100644 (file)
@@ -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
index 28bd9e5f875a0ab2d502084f28754cf7cd4cb941..1075d740153f13da60d27baad23420ce73394164 100644 (file)
@@ -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);
 
index 9fddb9c641896c2bc9fff0cc3237308c8f07933b..c325647faaa1b5e5dcb50e89f70bbf5f94bb1da8 100644 (file)
@@ -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];
index aeeba77c993e9626ec6c6d184a98405c02c3ccf3..ba2aaa61c6fe3bd54b66f75b24d576f167f0ebce 100644 (file)
@@ -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) {