wbenny / mini-tor

proof-of-concept implementation of tor protocol using Microsoft CNG/CryptoAPI
MIT License
393 stars 89 forks source link

Still hangs when host is unreachable #4

Closed n0isecontrol closed 7 years ago

n0isecontrol commented 7 years ago

Hey, first of all thank you for your work. I've discovered that if host is unreachable it still hangs at _mini/tor/tor_socket.cpp#L300_. I tried to just replace this line with tor_socket::close which can produce another loop at _/mini/tor/tor_socket.cpp#L96_.

You set tor_socket::state::ready _here, but also check just in the next loop_ if tor_socket::_state equals tor_socket::state::ready::closing so it cant reach break;.

Call stack: -> mini-tor.exe!mini::threading::thread::join(int timeout) Line 118 -> mini-tor.exe!mini::tor::tor_socket::set_state(mini::tor::tor_socket::state new_state) Line 306 -> mini-tor.exe!mini::tor::tor_socket::connect(mini::tor::onion_router * or) Line 53 -> mini-tor.exe!tor_client::extend_to(mini::tor::onion_router * onion_router) Line 65 -> mini-tor.exe!tor_client::extend_to_random(mini::flags flags, mini::collections::list<unsigned short,mini::allocator > or_ports) Line 47 -> mini-tor.exe!main(int argc, char * * argv) Line 259

Best Regards

wbenny commented 7 years ago

thank you for the bug report. it was caused by joining a non-started thread - initial value for the _thread_handle was INVALID_HANDLE_VALUE, which has the same value as "NtCurrentProcess()" macro (-1). so it was basically waiting for the process itself to end and causing deadlock.