[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] test.c: Try to create a more random temporary directory for our workspace (re: Bug#8638)
commit d1dc23c9386c6c85ec50c5b4d0a9077ffcb78683
Author: Peter Palfrader <peter@xxxxxxxxxxxxx>
Date: Thu Apr 4 18:05:14 2013 +0200
test.c: Try to create a more random temporary directory for our workspace (re: Bug#8638)
---
changes/bug8638 | 3 +++
src/test/test.c | 13 +++++++++----
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/changes/bug8638 b/changes/bug8638
new file mode 100644
index 0000000..3a790e5
--- /dev/null
+++ b/changes/bug8638
@@ -0,0 +1,3 @@
+ o Minor features
+ In our testsuite, create temporary directories with a bit more entropy
+ in their name to make name collissions less likely. Fixes bug 8638.
diff --git a/src/test/test.c b/src/test/test.c
index d3d3bd5..0b55f7b 100644
--- a/src/test/test.c
+++ b/src/test/test.c
@@ -88,8 +88,14 @@ setup_directory(void)
{
static int is_setup = 0;
int r;
+ char rnd[256], rnd32[256];
if (is_setup) return;
+/* Due to base32 limitation needs to be a multiple of 5. */
+#define RAND_PATH_BYTES 5
+ crypto_rand(rnd, RAND_PATH_BYTES);
+ base32_encode(rnd32, sizeof(rnd32), rnd, RAND_PATH_BYTES);
+
#ifdef _WIN32
{
char buf[MAX_PATH];
@@ -98,11 +104,11 @@ setup_directory(void)
if (!GetTempPathA(sizeof(buf),buf))
tmp = "c:\\windows\\temp";
tor_snprintf(temp_dir, sizeof(temp_dir),
- "%s\\tor_test_%d", tmp, (int)getpid());
+ "%s\\tor_test_%d_%s", tmp, (int)getpid(), rnd32);
r = mkdir(temp_dir);
}
#else
- tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d", (int) getpid());
+ tor_snprintf(temp_dir, sizeof(temp_dir), "/tmp/tor_test_%d_%s", (int) getpid(), rnd32);
r = mkdir(temp_dir, 0700);
#endif
if (r) {
@@ -2094,6 +2100,7 @@ main(int c, const char **v)
return 1;
}
crypto_set_tls_dh_prime(NULL);
+ crypto_seed_rng(1);
rep_hist_init();
network_init();
setup_directory();
@@ -2106,8 +2113,6 @@ main(int c, const char **v)
return 1;
}
- crypto_seed_rng(1);
-
atexit(remove_directory);
have_failed = (tinytest_main(c, v, testgroups) != 0);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits