commit: 32421ec602705b4b21bdeb2a26c069ad6736f119 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> AuthorDate: Sun Jan 26 19:38:34 2020 +0000 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> CommitDate: Sun Jan 26 19:38:34 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=32421ec6
qmerge: fix Coverity 125937 Time of check time of use Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> qmerge.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qmerge.c b/qmerge.c index 15017c1..156f262 100644 --- a/qmerge.c +++ b/qmerge.c @@ -1603,9 +1603,14 @@ static int unlink_empty(const char *buf) { struct stat st; - if (stat(buf, &st) != -1) + int fd; + + fd = open(buf, O_RDONLY); + if (fd != -1 && stat(buf, &st) != -1) { if (st.st_size == 0) return unlink(buf); + close(fd); + } return -1; }