From 48ed1657283aa69d96aca8ce4e4ee9dea829baaf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 21 Mar 2008 21:46:58 +0200 Subject: [PATCH] Few file descriptor cleanup and error handling fixes Closes: #443338 --- ChangeLog | 10 ++++++++++ debian/changelog | 2 ++ lib/parse.c | 6 +++--- src/archives.c | 3 ++- src/processarc.c | 7 ++++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b68e4d00..87c50284 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-03-21 Ian Jackson + + * 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 * dpkg-deb/extract.c (safe_fflush): Change return type from int to diff --git a/debian/changelog b/debian/changelog index ffd82402..22a4cf07 100644 --- a/debian/changelog +++ b/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 diff --git a/lib/parse.c b/lib/parse.c index 28bd9e5f..1075d740 100644 --- a/lib/parse.c +++ b/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); diff --git a/src/archives.c b/src/archives.c index 9fddb9c6..c325647f 100644 --- a/src/archives.c +++ b/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]; diff --git a/src/processarc.c b/src/processarc.c index aeeba77c..ba2aaa61 100644 --- a/src/processarc.c +++ b/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) { -- 2.39.5