commit aa7b569c5db43239a26ed1ed5703b1043536fb07 Author: David Goulet dgoulet@ev0ke.net Date: Sun Nov 10 21:15:47 2013 -0500
Fix: add a library cleanup flag
This flag is used to make sure we don't cleanup torsocks twice which could lead to out of bound memory access.
Signed-off-by: David Goulet dgoulet@ev0ke.net --- src/lib/torsocks.c | 9 +++++++++ src/lib/torsocks.h | 2 ++ 2 files changed, 11 insertions(+)
diff --git a/src/lib/torsocks.c b/src/lib/torsocks.c index f1de9c5..d97a598 100644 --- a/src/lib/torsocks.c +++ b/src/lib/torsocks.c @@ -47,6 +47,9 @@ struct configuration tsocks_config; */ struct onion_pool tsocks_onion_pool;
+/* Indicate if the library was cleaned up previously. */ +unsigned int tsocks_cleaned_up = 0; + /* * Set to 1 if the binary is set with suid or 0 if not. This is set once during * initialization so after that it can be read without any protection. @@ -530,10 +533,16 @@ void *tsocks_find_libc_symbol(const char *symbol, */ void tsocks_cleanup(void) { + if (tsocks_cleaned_up) { + return; + } + /* Cleanup every entries in the onion pool. */ onion_pool_destroy(&tsocks_onion_pool); /* Cleanup allocated memory in the config file. */ config_file_destroy(&tsocks_config.conf_file); /* Clean up logging. */ log_destroy(); + + tsocks_cleaned_up = 1; } diff --git a/src/lib/torsocks.h b/src/lib/torsocks.h index c5466a1..3e82a94 100644 --- a/src/lib/torsocks.h +++ b/src/lib/torsocks.h @@ -337,6 +337,8 @@ extern struct configuration tsocks_config; /* Global pool for .onion address. Initialized once in the constructor. */ extern struct onion_pool tsocks_onion_pool;
+extern unsigned int tsocks_cleaned_up; + int tsocks_connect_to_tor(struct connection *conn); void *tsocks_find_libc_symbol(const char *symbol, enum tsocks_sym_action action);
tor-commits@lists.torproject.org