From b1094fdec505088a39c94da79219d17c10baabef Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:39:34 +1000 Subject: [PATCH 1/6] Fix an incorrect comment on spawn_func spawn_func calls pthread_create on unix, not fork Fix on existing code split out of compat.c into compat_pthreads.c in c2f0d52b7fb9 --- changes/bug16115-spawn-comment | 6 ++++++ src/common/compat_pthreads.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changes/bug16115-spawn-comment diff --git a/changes/bug16115-spawn-comment b/changes/bug16115-spawn-comment new file mode 100644 index 0000000000..7792564688 --- /dev/null +++ b/changes/bug16115-spawn-comment @@ -0,0 +1,6 @@ + o Minor fixes (threads, comments): + - Fix an incorrect comment on spawn_func in compat_pthreads.c. + spawn_func calls pthread_create on unix, not fork + Patch by "teor". + Bugfix on unknown tor version (existing code split out of + compat.c into compat_pthreads.c in c2f0d52b7fb9 on 22 Sep 2013). diff --git a/src/common/compat_pthreads.c b/src/common/compat_pthreads.c index fdc504690b..487f7e5851 100644 --- a/src/common/compat_pthreads.c +++ b/src/common/compat_pthreads.c @@ -50,7 +50,8 @@ static pthread_attr_t attr_detached; static int threads_initialized = 0; /** Minimalist interface to run a void function in the background. On - * Unix calls fork, on win32 calls beginthread. Returns -1 on failure. + * Unix calls pthread_create, on win32 calls beginthread. Returns -1 on + * failure. * func should not return, but rather should call spawn_exit. * * NOTE: if data is used, it should not be allocated on the stack, From b3f79da0d589157948262d4a5c81969da789c0c4 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:43:46 +1000 Subject: [PATCH 2/6] Silence unused variable warnings in find_cipher_by_id Unused variable warnings were still generated under some versions of OpenSSL. Instead, make sure all variables are used under all versions. Fix on 496df21c89d1, not in any released version of tor. --- changes/bug16115-unused-find-cipher | 7 +++++++ src/common/tortls.c | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 changes/bug16115-unused-find-cipher diff --git a/changes/bug16115-unused-find-cipher b/changes/bug16115-unused-find-cipher new file mode 100644 index 0000000000..0f04d6795b --- /dev/null +++ b/changes/bug16115-unused-find-cipher @@ -0,0 +1,7 @@ + o Minor fixes (threads, comments): + - Silence unused variable warnings in find_cipher_by_id + Unused variable warnings were still generated under some versions + of OpenSSL. Instead, make sure all variables are used under all + versions of OpenSSL. + Patch by "teor". + Fix on 496df21c89d1, not in any released version of tor. diff --git a/src/common/tortls.c b/src/common/tortls.c index a4b6c487fe..70b9f0b240 100644 --- a/src/common/tortls.c +++ b/src/common/tortls.c @@ -1483,6 +1483,8 @@ find_cipher_by_id(const SSL *ssl, const SSL_METHOD *m, uint16_t cipher) } #endif (void) ssl; + (void) m; + (void) cipher; return 1; /* No way to search */ } From 2b73dbf2a4c2fcf42fdd2987b3fa72efdec3a222 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:48:46 +1000 Subject: [PATCH 3/6] Always initialise return value in compute_desc_id in rendcommon.c Fix on e6a581f126ba, released in 0.2.7.1-alpha. --- changes/bug16115-init-var | 4 ++++ src/or/rendcommon.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 changes/bug16115-init-var diff --git a/changes/bug16115-init-var b/changes/bug16115-init-var new file mode 100644 index 0000000000..e3e924a3e3 --- /dev/null +++ b/changes/bug16115-init-var @@ -0,0 +1,4 @@ + o Minor fixes (threads, comments): + - Always initialise return value in compute_desc_id in rendcommon.c + Patch by "teor". + Fix on e6a581f126ba, released in 0.2.7.1-alpha. diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index ec4353c409..0acca58713 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -1417,7 +1417,7 @@ rend_data_dup(const rend_data_t *data) static int compute_desc_id(rend_data_t *rend_data) { - int ret; + int ret = 0; unsigned replica; time_t now = time(NULL); From e0477de0e262e9009021cbd0556b7a9541d2192c Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:52:31 +1000 Subject: [PATCH 4/6] Remove undefined directive-in-macro in test_util_writepid clang 3.7 complains that using a preprocessor directive inside a macro invocation in test_util_writepid in test_util.c is undefined. Fix on 79e85313aa61 on 0.2.7.1-alpha. --- changes/bug16115-undef-directive-in-macro | 6 ++++++ src/test/test_util.c | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 changes/bug16115-undef-directive-in-macro diff --git a/changes/bug16115-undef-directive-in-macro b/changes/bug16115-undef-directive-in-macro new file mode 100644 index 0000000000..8031267cdf --- /dev/null +++ b/changes/bug16115-undef-directive-in-macro @@ -0,0 +1,6 @@ + o Minor fixes (threads, comments): + - Remove undefined directive-in-macro in test_util_writepid + clang 3.7 complains that using a preprocessor directive inside + a macro invocation in test_util_writepid in test_util.c is undefined. + Patch by "teor". + Fix on 79e85313aa61 on 0.2.7.1-alpha. diff --git a/src/test/test_util.c b/src/test/test_util.c index 30dc59844a..b0366db37f 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -4319,13 +4319,12 @@ test_util_writepid(void *arg) int n = sscanf(contents, "%lu\n%c", &pid, &c); tt_int_op(n, OP_EQ, 1); - tt_uint_op(pid, OP_EQ, + #ifdef _WIN32 - _getpid() + tt_uint_op(pid, OP_EQ, _getpid()); #else - getpid() + tt_uint_op(pid, OP_EQ, getpid()); #endif - ); done: tor_free(contents); From 383a27afc58b7a416fe0f30c80fdd069bc03d5d4 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:56:05 +1000 Subject: [PATCH 5/6] Ensure signing_key is non-NULL before accessing one of its members signing_key can be NULL in ed_key_init_from_file in routerkeys.c. Discovered by clang 3.7 address sanitizer. Fix on c03694938ed0, not in any released version of Tor. --- changes/bug16115-signing-key-NULL-check | 6 ++++++ src/or/routerkeys.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changes/bug16115-signing-key-NULL-check diff --git a/changes/bug16115-signing-key-NULL-check b/changes/bug16115-signing-key-NULL-check new file mode 100644 index 0000000000..3d4f05bc28 --- /dev/null +++ b/changes/bug16115-signing-key-NULL-check @@ -0,0 +1,6 @@ + o Minor fixes (threads, comments): + - Ensure signing_key is non-NULL before accessing one of its members + signing_key can be NULL in ed_key_init_from_file in routerkeys.c. + Discovered by clang 3.7 address sanitizer. + Patch by "teor". + Fix on c03694938ed0, not in any released version of Tor. diff --git a/src/or/routerkeys.c b/src/or/routerkeys.c index b17d1958f7..e79204cf09 100644 --- a/src/or/routerkeys.c +++ b/src/or/routerkeys.c @@ -152,7 +152,8 @@ ed_key_init_from_file(const char *fname, uint32_t flags, ED25519_PUBKEY_LEN)) { tor_log(severity, LD_OR, "Cert was for wrong key"); bad_cert = 1; - } else if (tor_cert_checksig(cert, &signing_key->pubkey, now) < 0 && + } else if (signing_key && + tor_cert_checksig(cert, &signing_key->pubkey, now) < 0 && (signing_key || cert->cert_expired)) { tor_log(severity, LD_OR, "Can't check certificate"); bad_cert = 1; From 6d8a2ff24f18cc008d3c180a191f5040c7b2e2ba Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 3 Jun 2015 03:58:28 +1000 Subject: [PATCH 6/6] Check for NULL values in getinfo_helper_onions Fix on 915c7438a77e in Tor 0.2.7.1-alpha. --- changes/bug16115-NULL-getinfo-onions | 4 ++++ src/or/control.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changes/bug16115-NULL-getinfo-onions diff --git a/changes/bug16115-NULL-getinfo-onions b/changes/bug16115-NULL-getinfo-onions new file mode 100644 index 0000000000..ec1661e18d --- /dev/null +++ b/changes/bug16115-NULL-getinfo-onions @@ -0,0 +1,4 @@ + o Minor fixes (threads, comments): + - Check for NULL values in getinfo_helper_onions + Patch by "teor". + Fix on 915c7438a77e in Tor 0.2.7.1-alpha. diff --git a/src/or/control.c b/src/or/control.c index 2eaad4e373..7a113f2c1c 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -2193,7 +2193,7 @@ getinfo_helper_onions(control_connection_t *control_conn, { smartlist_t *onion_list = NULL; - if (!strcmp(question, "onions/current")) { + if (control_conn && !strcmp(question, "onions/current")) { onion_list = control_conn->ephemeral_onion_services; } else if (!strcmp(question, "onions/detached")) { onion_list = detached_onion_services; @@ -2201,10 +2201,14 @@ getinfo_helper_onions(control_connection_t *control_conn, return 0; } if (!onion_list || smartlist_len(onion_list) == 0) { - *errmsg = "No onion services of the specified type."; + if (errmsg) { + *errmsg = "No onion services of the specified type."; + } return -1; } - *answer = smartlist_join_strings(onion_list, "\r\n", 0, NULL); + if (answer) { + *answer = smartlist_join_strings(onion_list, "\r\n", 0, NULL); + } return 0; }