aboutsummaryrefslogtreecommitdiff
path: root/qpkg.c
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2020-01-25 11:01:03 +0100
committerFabian Groffen <grobian@gentoo.org>2020-01-25 11:01:03 +0100
commitadedae3b3673d3797ba2ba381acf04c24c38b309 (patch)
tree25b4b136d4f6a1f92511c537c4230e6af4082a32 /qpkg.c
parentqpkg: try to fix Coverity 206549 Time of check, time of use (diff)
downloadportage-utils-adedae3b3673d3797ba2ba381acf04c24c38b309.tar.gz
portage-utils-adedae3b3673d3797ba2ba381acf04c24c38b309.tar.bz2
portage-utils-adedae3b3673d3797ba2ba381acf04c24c38b309.zip
qpkg: try 2 at Coverity 206549 Time of check time of use
Signed-off-by: Fabian Groffen <grobian@gentoo.org>
Diffstat (limited to 'qpkg.c')
-rw-r--r--qpkg.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/qpkg.c b/qpkg.c
index 6aa5f76..3602acf 100644
--- a/qpkg.c
+++ b/qpkg.c
@@ -257,9 +257,16 @@ qpkg_make(depend_atom *atom)
}
pclose(fp);
+ if ((i = open(tbz2, O_WRONLY)) < 0) {
+ warnp("failed to open '%s': %s", tbz2, strerror(errno));
+ free(buf);
+ return 1;
+ }
+
/* get offset where xpak will start */
- 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;
}
@@ -271,12 +278,6 @@ 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 (fstat(i, &st) == -1) {
warnp("could not stat '%s': %s", tbz2, strerror(errno));