aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2016-06-19 23:06:17 -0400
committerMike Frysinger <vapier@gentoo.org>2016-06-19 23:06:17 -0400
commitf2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd (patch)
tree312665e86069722af21cf3f2bfdb4712d3c254a2
parentpaxmacho: fix readmacho fd leakage on error (diff)
downloadpax-utils-f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd.tar.gz
pax-utils-f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd.tar.bz2
pax-utils-f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd.zip
paxelf: use fstat instead of stat && open
This fixes a minor race condition.
-rw-r--r--paxelf.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/paxelf.c b/paxelf.c
index a353e57..5b6fe24 100644
--- a/paxelf.c
+++ b/paxelf.c
@@ -629,19 +629,19 @@ elfobj *_readelf(const char *filename, int read_only)
struct stat st;
int fd;
- if (stat(filename, &st) == -1)
- return NULL;
-
if ((fd = open(filename, (read_only ? O_RDONLY : O_RDWR))) == -1)
return NULL;
- /* make sure we have enough bytes to scan e_ident */
- if (st.st_size <= EI_NIDENT) {
-close_fd_and_return:
+ if (fstat(fd, &st) == -1) {
+ close_fd_and_return:
close(fd);
return NULL;
}
+ /* make sure we have enough bytes to scan e_ident */
+ if (st.st_size <= EI_NIDENT)
+ goto close_fd_and_return;
+
ret = readelf_fd(filename, fd, st.st_size);
if (ret == NULL)
goto close_fd_and_return;