From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id CA513138350 for ; Sat, 25 Jan 2020 09:45:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 7DD06E082D; Sat, 25 Jan 2020 09:45:16 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 640DEE082D for ; Sat, 25 Jan 2020 09:45:16 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id BA2C534E2BD for ; Sat, 25 Jan 2020 09:45:14 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 659A9D7 for ; Sat, 25 Jan 2020 09:45:12 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1579945458.db5cb274ad76778091619b8c7e38a7c0134d5a04.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: / X-VCS-Repository: proj/portage-utils X-VCS-Files: qpkg.c X-VCS-Directories: / X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: db5cb274ad76778091619b8c7e38a7c0134d5a04 X-VCS-Branch: master Date: Sat, 25 Jan 2020 09:45:12 +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-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: e687fb0b-d589-4a6f-a67b-e6e6e1883fe8 X-Archives-Hash: 6f30cca198db619608a296c50f36cd77 commit: db5cb274ad76778091619b8c7e38a7c0134d5a04 Author: Fabian Groffen gentoo org> AuthorDate: Sat Jan 25 09:44:18 2020 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Sat Jan 25 09:44:18 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=db5cb274 qpkg: try to fix Coverity 206549 Time of check, time of use Signed-off-by: Fabian Groffen gentoo.org> qpkg.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/qpkg.c b/qpkg.c index 1535f05..6aa5f76 100644 --- a/qpkg.c +++ b/qpkg.c @@ -271,17 +271,25 @@ qpkg_make(depend_atom *atom) xpak_argv[1] = NULL; xpak_create(AT_FDCWD, tbz2, 1, xpak_argv, 1, verbose); + if ((i = open(tbz2, O_WRONLY | O_APPEND)) < 0) { + warnp("failed to open '%s': %s", tbz2, strerror(errno)); + free(buf); + return 1; + } + /* calculate the number of bytes taken by the xpak archive */ - if (stat(tbz2, &st) == -1) { + if (fstat(i, &st) == -1) { warnp("could not stat '%s': %s", tbz2, strerror(errno)); + close(i); free(buf); return 1; } xpaksize = st.st_size - xpaksize; /* save tbz2 tail: OOOOSTOP */ - if ((fp = fopen(tbz2, "a")) == NULL) { + if ((fp = fdopen(i, "a")) == NULL) { warnp("could not open '%s': %s", tbz2, strerror(errno)); + close(i); free(buf); return 1; } @@ -294,8 +302,7 @@ qpkg_make(depend_atom *atom) unlink(filelist); /* create dirs, if necessary */ - snprintf(buf, buflen, "%s/%s", - qpkg_bindir, atom->CATEGORY); + snprintf(buf, buflen, "%s/%s", qpkg_bindir, atom->CATEGORY); mkdir_p(buf, 0755); snprintf(buf, buflen, "%s/%s/%s.tbz2",