Module Name: src Committed By: elad Date: Sat May 2 06:01:30 UTC 2009
Modified Files: src/usr.sbin/paxctl: paxctl.c Log Message: PR/41332: Jason V. Miller: paxctl(8) leaks file descriptors Always close(fd) before returning. Thanks for the report! To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/paxctl/paxctl.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/paxctl/paxctl.c diff -u src/usr.sbin/paxctl/paxctl.c:1.9 src/usr.sbin/paxctl/paxctl.c:1.10 --- src/usr.sbin/paxctl/paxctl.c:1.9 Sun Jan 18 10:01:34 2009 +++ src/usr.sbin/paxctl/paxctl.c Sat May 2 06:01:30 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: paxctl.c,v 1.9 2009/01/18 10:01:34 lukem Exp $ */ +/* $NetBSD: paxctl.c,v 1.10 2009/05/02 06:01:30 elad Exp $ */ /*- * Copyright (c) 2006 Elad Efrat <e...@netbsd.org> @@ -34,7 +34,7 @@ #include <sys/cdefs.h> #ifndef lint #ifdef __RCSID -__RCSID("$NetBSD: paxctl.c,v 1.9 2009/01/18 10:01:34 lukem Exp $"); +__RCSID("$NetBSD: paxctl.c,v 1.10 2009/05/02 06:01:30 elad Exp $"); #endif #endif /* not lint */ @@ -204,11 +204,13 @@ if (read(fd, &e, sizeof(e)) != sizeof(e)) { warn("Can't read ELF header from `%s'", name); + (void)close(fd); return 1; } if (memcmp(e.h32.e_ident, ELFMAG, SELFMAG) != 0) { warnx("Bad ELF magic from `%s' (maybe it's not an ELF?)", name); + (void)close(fd); return 1; } @@ -227,6 +229,7 @@ } else { warnx("Bad ELF size %d from `%s' (maybe it's not an ELF?)", (int)e.h32.e_ehsize, name); + (void)close(fd); return 1; } @@ -234,6 +237,7 @@ if ((size_t)pread(fd, &p, PHSIZE, (off_t)EH(e_phoff) + i * PHSIZE) != PHSIZE) { warn("Can't read program header data from `%s'", name); + (void)close(fd); return 1; } @@ -242,6 +246,7 @@ if (pread(fd, &n, NHSIZE, (off_t)PH(p_offset)) != NHSIZE) { warn("Can't read note header from `%s'", name); + (void)close(fd); return 1; } if (NH(n_type) != ELF_NOTE_TYPE_PAX_TAG || @@ -251,6 +256,7 @@ if (pread(fd, &pax_tag, sizeof(pax_tag), PH(p_offset) + NHSIZE) != sizeof(pax_tag)) { warn("Can't read pax_tag from `%s'", name); + (void)close(fd); return 1; } if (memcmp(pax_tag.name, ELF_NOTE_PAX_NAME, @@ -258,6 +264,7 @@ warn("Unknown pax_tag name `%*.*s' from `%s'", ELF_NOTE_PAX_NAMESZ, ELF_NOTE_PAX_NAMESZ, pax_tag.name, name); + (void)close(fd); return 1; } ok = 1; @@ -287,6 +294,7 @@ if (!pax_flags_sane(SWAP(pax_tag.flags))) { warnx("New flags 0x%x don't make sense", (uint32_t)SWAP(pax_tag.flags)); + (void)close(fd); return 1; }