Module Name: src Committed By: christos Date: Sat May 2 16:19:36 UTC 2009
Modified Files: src/usr.sbin/paxctl: paxctl.c Log Message: easier done with a goto instead of closing in each error. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 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.10 src/usr.sbin/paxctl/paxctl.c:1.11 --- src/usr.sbin/paxctl/paxctl.c:1.10 Sat May 2 02:01:30 2009 +++ src/usr.sbin/paxctl/paxctl.c Sat May 2 12:19:36 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: paxctl.c,v 1.10 2009/05/02 06:01:30 elad Exp $ */ +/* $NetBSD: paxctl.c,v 1.11 2009/05/02 16:19:36 christos 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.10 2009/05/02 06:01:30 elad Exp $"); +__RCSID("$NetBSD: paxctl.c,v 1.11 2009/05/02 16:19:36 christos Exp $"); #endif #endif /* not lint */ @@ -193,25 +193,23 @@ char name[ELF_NOTE_PAX_NAMESZ]; uint32_t flags; } pax_tag; - int fd, size, ok = 0, flagged = 0, swap; + int fd, size, ok = 0, flagged = 0, swap, error = 1; size_t i; fd = open(name, list ? O_RDONLY: O_RDWR, 0); if (fd == -1) { warn("Can't open `%s'", name); - return 1; + return error; } if (read(fd, &e, sizeof(e)) != sizeof(e)) { warn("Can't read ELF header from `%s'", name); - (void)close(fd); - return 1; + goto out; } 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; + goto out; } if (e.h32.e_ehsize == sizeof(e.h32)) { @@ -229,16 +227,14 @@ } 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; + goto out; } for (i = 0; i < EH(e_phnum); i++) { - if ((size_t)pread(fd, &p, PHSIZE, (off_t)EH(e_phoff) + i * PHSIZE) != - PHSIZE) { + 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; + goto out; } if (PH(p_type) != PT_NOTE) @@ -246,8 +242,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; + goto out; } if (NH(n_type) != ELF_NOTE_TYPE_PAX_TAG || NH(n_descsz) != ELF_NOTE_PAX_DESCSZ || @@ -256,16 +251,14 @@ 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; + goto out; } if (memcmp(pax_tag.name, ELF_NOTE_PAX_NAME, sizeof(pax_tag.name)) != 0) { 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; + goto out; } ok = 1; @@ -282,9 +275,7 @@ (void)printf("PaX flags:\n"); pax_printflags(name, many, SWAP(pax_tag.flags)); - flagged = 1; - break; } @@ -294,8 +285,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; + goto out; } if (pwrite(fd, &pax_tag, sizeof(pax_tag), @@ -304,20 +294,21 @@ break; } - (void)close(fd); - if (!ok) { warnx("Could not find an ELF PaX PT_NOTE section in `%s'", name); - return 1; + goto out; } + error = 0; if (list && !flagged) { if (many) (void)printf("%s: ", name); (void)printf("No PaX flags.\n"); } - return 0; +out: + (void)close(fd); + return error; } int