aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_dir_handle_get.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-04-03 10:16:18 -0400
committerNick Mathewson <nickm@torproject.org>2019-04-03 10:16:18 -0400
commit367dd9cf0226c087d49225a20415e9a199d2d71f (patch)
tree76b352938759fb151dab2091497a91c74abb0b06 /src/test/test_dir_handle_get.c
parentde76862fd6177acd8c5b801af4df73bfab5d98ac (diff)
downloadtor-367dd9cf0226c087d49225a20415e9a199d2d71f.tar.gz
tor-367dd9cf0226c087d49225a20415e9a199d2d71f.zip
30001: Fix a race condition in test_dir_handle_get.c
Previously we used time(NULL) to set the Expires: header in our HTTP responses. This made the actual contents of that header untestable, since the unit tests have no good way to override time(), or to see what time() was at the exact moment of the call to time() in dircache.c. This gave us a race in dir_handle_get/status_vote_next_bandwidth, where the time() call in dircache.c got one value, and the call in the tests got another value. I'm applying our regular solution here: using approx_time() so that the value stays the same between the code and the test. Since approx_time() is updated on every event callback, we shouldn't be losing any accuracy here. Fixes bug 30001. Bug introduced in fb4a40c32c4a7e5; not in any released Tor.
Diffstat (limited to 'src/test/test_dir_handle_get.c')
-rw-r--r--src/test/test_dir_handle_get.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/test_dir_handle_get.c b/src/test/test_dir_handle_get.c
index c3a17e7309..e57bd02584 100644
--- a/src/test/test_dir_handle_get.c
+++ b/src/test/test_dir_handle_get.c
@@ -2526,7 +2526,7 @@ test_dir_handle_get_status_vote_next_bandwidth(void* data)
/* Check cache lifetime */
char expbuf[RFC1123_TIME_LEN+1];
- time_t now = time(NULL);
+ time_t now = approx_time();
/* BANDWIDTH_CACHE_LIFETIME is defined in dircache.c. */
format_rfc1123_time(expbuf, (time_t)(now + 30*60));
char *expires = NULL;