tunsocks
tunsocks copied to clipboard
Crash when only specifying a port for SOCKS
Running tunsocks -D 8080 crashes with...
2018-07-06 15:13:19.690392+0930 tunsocks[84093:18868044] detected buffer overflow
...
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x00007fff53c44b6e libsystem_kernel.dylib`__pthread_kill + 10
frame #1: 0x00007fff53e0f080 libsystem_pthread.dylib`pthread_kill + 333
frame #2: 0x00007fff53ba01ae libsystem_c.dylib`abort + 127
frame #3: 0x00007fff53ba0321 libsystem_c.dylib`abort_report_np + 177
frame #4: 0x00007fff53bc4bf5 libsystem_c.dylib`__chk_fail + 48
frame #5: 0x00007fff53bc4bc5 libsystem_c.dylib`__chk_fail_overflow + 16
frame #6: 0x00007fff53bc5110 libsystem_c.dylib`__memcpy_chk + 37
frame #7: 0x000000010000fc61 tunsocks`socks_listen(base=0x0000000100402290, host=<unavailable>, port=<unavailable>, keep_alive=<unavailable>) at socks.c:399 [opt]
frame #8: 0x00000001000119c2 tunsocks`main(argc=3, argv=0x00007ffeefbff898) at main.c:280 [opt]
frame #9: 0x00007fff53af4015 libdyld.dylib`start + 1
frame #10: 0x00007fff53af4015 libdyld.dylib`start + 1
This fixes it (by pretending IPv6 doesn't exist)
diff --git a/src/socks.c b/src/socks.c
index 30d1803..420fab0 100644
--- a/src/socks.c
+++ b/src/socks.c
@@ -386,7 +387,7 @@ socks_listen(struct event_base *base, const char *host, const char *port,
s->keep_alive = keep_alive;
memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_UNSPEC;
+ hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
ret = getaddrinfo(host, port, &hints, &result);