1 |
commit: 32421ec602705b4b21bdeb2a26c069ad6736f119 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Jan 26 19:38:34 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Jan 26 19:38:34 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=32421ec6 |
7 |
|
8 |
qmerge: fix Coverity 125937 Time of check time of use |
9 |
|
10 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
11 |
|
12 |
qmerge.c | 7 ++++++- |
13 |
1 file changed, 6 insertions(+), 1 deletion(-) |
14 |
|
15 |
diff --git a/qmerge.c b/qmerge.c |
16 |
index 15017c1..156f262 100644 |
17 |
--- a/qmerge.c |
18 |
+++ b/qmerge.c |
19 |
@@ -1603,9 +1603,14 @@ static int |
20 |
unlink_empty(const char *buf) |
21 |
{ |
22 |
struct stat st; |
23 |
- if (stat(buf, &st) != -1) |
24 |
+ int fd; |
25 |
+ |
26 |
+ fd = open(buf, O_RDONLY); |
27 |
+ if (fd != -1 && stat(buf, &st) != -1) { |
28 |
if (st.st_size == 0) |
29 |
return unlink(buf); |
30 |
+ close(fd); |
31 |
+ } |
32 |
return -1; |
33 |
} |