diff options
author | Fabian Groffen <grobian@gentoo.org> | 2020-01-25 10:44:18 +0100 |
---|---|---|
committer | Fabian Groffen <grobian@gentoo.org> | 2020-01-25 10:44:18 +0100 |
commit | db5cb274ad76778091619b8c7e38a7c0134d5a04 (patch) | |
tree | 7870c2821ffd7685d62cc19ce795d73b942a722a /qpkg.c | |
parent | qpkg: fix syntax error (diff) | |
download | portage-utils-db5cb274ad76778091619b8c7e38a7c0134d5a04.tar.gz portage-utils-db5cb274ad76778091619b8c7e38a7c0134d5a04.tar.bz2 portage-utils-db5cb274ad76778091619b8c7e38a7c0134d5a04.zip |
qpkg: try to fix 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.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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", |