From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 832C61382AC for ; Mon, 20 Jun 2016 03:08:33 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B96421425B; Mon, 20 Jun 2016 03:08:27 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id A717414267 for ; Mon, 20 Jun 2016 03:08:26 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AC2C43408D4 for ; Mon, 20 Jun 2016 03:08:25 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4F9D02424 for ; Mon, 20 Jun 2016 03:08:22 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1466391977.f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd.vapier@gentoo> Subject: [gentoo-commits] proj/pax-utils:master commit in: / X-VCS-Repository: proj/pax-utils X-VCS-Files: paxelf.c X-VCS-Directories: / X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd X-VCS-Branch: master Date: Mon, 20 Jun 2016 03:08:22 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 38ecfcf6-28f9-4fb0-9f27-41bed1817c58 X-Archives-Hash: 236b317bcfc726461a4ed31dd08efda2 commit: f2b83d5bfd9904ad32cb6f2f5bd42fea07f8fddd Author: Mike Frysinger gentoo org> AuthorDate: Mon Jun 20 03:06:17 2016 +0000 Commit: Mike Frysinger gentoo 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;