diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-08-14 13:16:46 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2020-09-17 09:17:49 -0400 |
commit | 4e8cb410a7db74b8099df3e17f38344e8201913b (patch) | |
tree | 8a038741111b3d4a9f5e6aa95e28aa18862b71c1 /src/test/test_util.c | |
parent | ebaa1a1d23d114c16ef12845a82d2bb958de3f7f (diff) | |
download | tor-4e8cb410a7db74b8099df3e17f38344e8201913b.tar.gz tor-4e8cb410a7db74b8099df3e17f38344e8201913b.zip |
Resolve some coverity complaints in test_util_glob().
Coverity's first complaint was that we didn't check the return
values from chmod. That's easily fixed.
Coverity's second complaint was that there were code paths where we pass
NULL to chmod. For example, if this line failed, we'd "goto done",
and then pass NULL to chmod.
tt_ptr_op(dirname, OP_NE, NULL);
Closes #40103. Bug not in any released Tor.
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index 0e2550d5c5..cab48cd514 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4475,11 +4475,11 @@ test_util_glob(void *ptr) tor_asprintf(&forbidden_forbidden, "%s"PATH_SEPARATOR"forbidden"PATH_SEPARATOR"forbidden",dirname); #ifndef _WIN32 - chmod(forbidden, 0700); + tt_int_op(0, OP_EQ, chmod(forbidden, 0700)); #endif tt_int_op(0, OP_EQ, create_test_directory_structure(forbidden)); #ifndef _WIN32 - chmod(forbidden, 0); + tt_int_op(0, OP_EQ, chmod(forbidden, 0)); #endif #define TEST(input) \ @@ -4638,10 +4638,10 @@ test_util_glob(void *ptr) done: #ifndef _WIN32 - chmod(forbidden, 0700); - chmod(dir1_forbidden, 0700); - chmod(dir2_forbidden, 0700); - chmod(forbidden_forbidden, 0700); + (void) chmod(forbidden, 0700); + (void) chmod(dir1_forbidden, 0700); + (void) chmod(dir2_forbidden, 0700); + (void) chmod(forbidden_forbidden, 0700); #endif tor_free(dir1); tor_free(dir2); @@ -4825,10 +4825,20 @@ test_util_get_glob_opened_files(void *ptr) done: #ifndef _WIN32 - chmod(forbidden, 0700); - chmod(dir1_forbidden, 0700); - chmod(dir2_forbidden, 0700); - chmod(forbidden_forbidden, 0700); + { + int chmod_failed = 0; + if (forbidden) + chmod_failed |= chmod(forbidden, 0700); + if (dir1_forbidden) + chmod_failed |= chmod(dir1_forbidden, 0700); + if (dir2_forbidden) + chmod_failed |= chmod(dir2_forbidden, 0700); + if (forbidden_forbidden) + chmod_failed |= chmod(forbidden_forbidden, 0700); + if (chmod_failed) { + TT_FAIL(("unable to chmod a file on cleanup: %s", strerror(errno))); + } + } #endif tor_free(dir1); tor_free(dir2); |