aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;