Skip to content

Commit 372a3d5

Browse files
committed
CDRIVER-2178 TOCTOU warning in example code
Coverity warns about time-of-check, time-of-use race in mongoc-dump.c.
1 parent d573130 commit 372a3d5

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

examples/mongoc-dump.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,15 @@
2323
static bool
2424
mongoc_dump_mkdir_p (const char *path, int mode)
2525
{
26+
int r;
27+
2628
#ifdef _WIN32
27-
if (0 != _access (path, 0)) {
28-
if (0 != _mkdir (path)) {
29-
return false;
30-
}
31-
}
29+
r = _mkdir (path);
3230
#else
33-
if (0 != access (path, F_OK)) {
34-
if (0 != mkdir (path, mode)) {
35-
return false;
36-
}
37-
}
31+
r = mkdir (path, mode);
3832
#endif
3933

40-
return true;
34+
return (r == 0 || errno == EEXIST);
4135
}
4236

4337

@@ -57,13 +51,9 @@ mongoc_dump_collection (mongoc_client_t *client,
5751

5852
path = bson_strdup_printf ("dump/%s/%s.bson", database, collection);
5953
#ifdef _WIN32
60-
if (0 == _access (path, 0)) {
61-
_unlink (path);
62-
}
54+
_unlink (path);
6355
#else
64-
if (0 == access (path, F_OK)) {
65-
unlink (path);
66-
}
56+
unlink (path);
6757
#endif
6858

6959
stream = fopen (path, "w");

0 commit comments

Comments
 (0)