commit: f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Mon Jun 20 03:06:17 2016 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Mon Jun 20 03:06:17 2016 +0000
URL: https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=f2b83d5b
paxelf: use fstat instead of stat && open
This fixes a minor race condition.
paxelf.c | 12 ++++++------
1 file 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;