Commit Graph

68 Commits (3e791fd797ce323a8e0e4148d13ee13ffd315d12)

Author SHA1 Message Date
rofl0r 3e791fd797 make sure allocator thread is only used if proxy_dns is requested 2020-09-20 18:21:40 +01:00
rofl0r 962373e5c6 getaddrinfo: fix behaviour when node is null and !passive
according to the spec, if these 2 conditions hold, the name shall
resolve to localhost.

closes #292
2019-07-21 14:27:55 +01:00
rofl0r de4460fbd1 proxy_getaddrinfo: don't use sizeof(struct sockaddr_storage) for addr_len
this should fix an issue which seems to be mac's bind() only accepting
sizeof(struct sockaddr_in) for AF_INET.

ref: https://github.com/rofl0r/microsocks/issues/19
2019-05-25 02:23:38 +01:00
rofl0r 5ad7c2a183 proxy_getaddrinfo: implement support for numeric ipv6
closes #282
2019-04-25 14:36:08 +01:00
rofl0r 5c8f9a2922 shrink huge log buffer 2019-02-28 13:22:13 +00:00
rofl0r 49bf4ba772 replace getservbyname_r ifdef hacks with configure check
this should make it work automatically on any new platform without
having to add yet another ifdef hack.
should fix issues with android (#265).
additionally the code for the systems lacking GNU-compatible getservbyname_r()
is now guarded with a mutex, which prevents possible races, therefore
resolving the ancient "TODO" item.
2018-12-02 13:48:43 +00:00
amyangfei eb36238c8a remove unused variable 2018-08-26 06:18:20 +01:00
amyangfei 275e64499e Fix select_proxy dead loop in round_roubin_chain
Fix issue #147.
If all proxies are in DOWN_STATE or BUSY_STATE state, select_proxy will run
forever in an infinite loop. When all proxies are not available, we wait some
intervals and retry. The wait time starts with 10 milliseconds and is
increased by 10 milliiseconds in each loop. 14 loops sums up with 1.05 second.
2018-08-23 12:40:27 +01:00
rofl0r 49d8ac9338 accept proper RFC1929 auth subnegotiation version field
this was wrongly fixed in 06c20ed394

instead of reverting we now accept the correct version
(version field containing 1) plus the incorrect version (5) given by some
proxyservers in the wild. curl accepts both forms too.

closing #224
addressing #221
2018-05-29 18:59:30 +01:00
rofl0r 06c20ed394 fix socks5 username/password auth
the version field in the auth check needs to be 5, not 1.

closes #221
2018-02-11 14:59:27 +00:00
WHR 35a674bdbc configure: Solaris detection, ld 'soname' option auto detection; other Solaris related fixes 2018-01-11 00:45:40 +08:00
Antonio Quartulli 46647bee44 fix memory leak
don't leak variable 'space' when the host is numeric

Signed-off-by: Antonio Quartulli <a@unstable.cc>
2017-08-28 15:19:43 +01:00
rofl0r bf6eeff75a check snprintf return value for error 2016-12-20 22:18:21 +00:00
Carlos Maddela 5ed5089733 Avoid using %n$ operand number formats to compile cleanly with ISO C. 2016-12-13 20:27:56 +00:00
Carlos Maddela 0bd2130352 Fix spelling in log message: doesnt -> doesn't 2016-12-05 14:10:09 +11:00
forkbomber cf9a16de06 core.c: add HOST header to each CONNECT request
fixes #92
closes #93
2016-10-16 19:43:00 +00:00
Jay Taylor 0f6b226b15 Fix random_chain on Mac OS X
On Mac OS X, random chain was broken and returned always the last proxy from the
config file.  Use fix as suggested by @ravomavain.

Closes #75.
2016-10-14 21:49:01 +00:00
rofl0r 2237749567 preliminary ipv6 support
only basic testing was done (with 2 socks5 proxies listening on ::1)
but seems to work as intended.

ipv6 support for the hostsreader (/etc/hosts) is not implemented so far.
2015-08-10 17:00:26 +01:00
rofl0r 9969dd3a22 fix socks5 bug: always requested user auth cap
since "user" always points to a statically allocated string buffer,
the test for if(user)... was bogus.
use ulen instead.

this bug should only be visible on socks servers that require auth
if username was not passed, so it was probably not really an issue.
2015-06-14 12:10:32 +01:00
rofl0r ae16ae9fc9 remove commented-out code 2015-06-14 09:57:05 +01:00
rofl0r 338b9ce4e3 whitespace fixes for proxytype switch block 2015-06-13 20:32:15 +01:00
rofl0r c6553c2cc5 replace string manip. in HTTP setup code with single snprintf 2015-06-13 20:21:59 +01:00
rofl0r 49adb6ce29 simplify socks5 buffer setup code 2015-06-13 19:02:11 +01:00
rofl0r c7fa7bf86a simplify start_chain struct setup 2015-06-13 18:37:57 +01:00
rofl0r 2182eff358 fix segfault in DNS mapping lookup code
the allocatorthread got pointers to RAM which were reallocated
behind the back, and if realloc() couldn't grow in-place, lead
to segfaults in applications that do a lot of DNS-lookups such
as webbrowsers.

closes #66
closes #31

thanks to @ravomavain for tracking down the issue.
2015-06-06 11:43:53 +01:00
rofl0r ba61b48fd7 fix compilation with openbsd
closes #52
2015-04-08 11:09:48 +01:00
rofl0r 4fb7eb0532 replace problematic hostentdb with hostsreader
the hostentdb introduced between 4.2 and 4.3
(via af5c6f0c6a )
had several issues:
- it caused breakage on FreeBSD and was commented out there
- prevented usage of the hostdb when proxy_dns was turned off
  (issue #42)
- required dynamic memory allocation which was accessed from several
  threads
- wouldnt reflect changes to the hosts file made during program run

the only sensible solution is to remove the hostentdb and replace it
with a home-grown hosts parser (we can't use gethostent() since
that would mess up the gethostent()-state from different threads).

the new parser used here is deliberately held simple and only meant
to provide the user with means to reference hardcoded ipv4 addresses
via his hosts file.

fixes #42
2014-11-14 12:33:58 +01:00
rofl0r 530fee89ce proxy_getaddrinfo: don't use strncpy
the strncpy function is both dangerous and slow.
dangerous because it doesn't do what the naive programmer expects
(bounded strcpy), and slow because it pads the entire bufsize
with zeroes.
2014-01-22 22:22:24 +01:00
rofl0r b76aa653c9 proxy_getaddrinfo: fix case when func was used in lieu of inet_aton 2014-01-22 16:13:20 +01:00
rofl0r f868928c4b fix incorrect poll.h inclusion
sys/poll.h is a glibc legacy alias for poll.h.
the latter is specified by POSIX, the former not.
on glibc one of them just includes the other so it doesnt hurt.
2014-01-08 14:57:13 +01:00
crass f603e50cb3 Add support for round robin mode. 2013-06-26 12:22:11 +02:00
rofl0r af5c6f0c6a replace hostent lookup with better performing in-memory copy.
the central dns resolver function proxy_gethostbyname() used
to iterate over the gethostent() db (/etc/hosts) on each dns
request.
since this is not threadsafe, we synchronized access to it
previously using mutexes. the parsing of this file is slow,
and blocking all threads to do it even moreso.
since gethostent_r() is only available on a few platforms,
i decided to read the hostent db once and then use a quick
in-memory lookup on further usage.

+ some further refactoring.
2012-11-08 01:18:19 +01:00
rofl0r c698d48c03 move stringfromipv4 into common.c 2012-11-07 22:00:03 +01:00
rofl0r 03ee84060e remove THREAD_SAFE ifdefs. from now on, pthreads are required.
additionally we have some explicit init and deinit routines for
core.c now, so that we dont need to share variables with
libproxychains.c.
2012-11-07 21:31:19 +01:00
rofl0r d0abc93c74 preliminary first fork-safe version
instead of allocating memory in the child, we now use the allocator
thread to do all the necessary allocations himself.
additionally we provide a clean API to query the ip <-> dns mapping.
these functions connect via a pipe to the allocator thread, and
exchange messages.

further cleanup is needed, but it seems to work so far.
thread-safety is not yet guaranteed.

closes #1
2012-11-07 21:31:11 +01:00
rofl0r 25afe98b20 failed attempt to use shared memory for the ip <-> dns mapping
this is in order to get irssi, which forks for DNS lookups,
and similar programs, to work as intended.

in a previous attempt i learned that shared memory created in a
child process is not visible to the parent;
in this attempt i spin off a thread from the parent which listens
on a pipe and manages the shared memory allocation from the parent
address-space. however this doesnt work as expected:
memory allocated in the parent after the child forked is not visi-
ble to the child as well.

so what happens is: irssi starts a child process, the thread allocs
memory and hands it to the child, the child attempts to write and
segfaults. however irssi doesnt crash. since now the memory is
already allocated, doing the dns lookup again will succeed.

i.e. the dns lookup works now in irssi by luck.
all but the first dns lookups will suceed.

however this is not good enough for me to be satisfied, i commit
this only for documentation purposes.
2012-11-07 16:49:14 +01:00
rofl0r e05cafc8e2 put a mutex lock around gethostent() usage, to prevent internal
races. the external usage was covered by the latest commit.
2012-11-04 05:23:51 +01:00
rofl0r 2d58820635 proxy_gethostbyname: fix thread safety issues arising from ...
gethostent() usage.

also set hostent.h_aliases member to a valid pointer.
2012-11-04 05:02:57 +01:00
rofl0r bddb79a286 fix bug which lead to segfault in ubuntu 12.04 telnet
it called gethostbyname and expected that the h->h_name was set.

this code path here which gets only active if the passed name
equals the gethostname() result failed to set a couple of values.

additionally fixed usage of strncpy, which causes the entire
memory buffer to be written, even when the string is much shorter.

a similar bugfix was independently discovered by semion laptev, but my
version is threadsafe - his version introduces a new static buffer,
even though we have plenty of thread-safe space reserved exactly
for this usage case, thus causing a regression.
2012-11-04 01:00:58 +01:00
rofl0r 108610e30e core.c: add getservbyname_r replacement function for mac 2012-08-06 01:26:03 +02:00
rofl0r 0f1bc719fd put base64 variable to the place it gets used 2012-08-04 17:55:37 +02:00
rofl0r 068e088a8b tunnel_to: use better suited type 2012-08-03 10:43:59 +02:00
rofl0r ab3ca31871 getaddrinfo: cosmetics 2012-07-16 01:34:00 +02:00
rofl0r 037edbcb8e proxy_getaddrinfo: fix segfault when hints is NULL 2012-07-16 01:19:30 +02:00
rofl0r 40edf758ee make getaddrinfo threadsafe 2012-07-16 01:05:28 +02:00
rofl0r 4b999cdae7 use threadsafe getservbyname_r 2012-07-14 17:59:56 +02:00
rofl0r 71e15e2edd simplify log func 2012-07-14 17:59:06 +02:00
rofl0r 3004240462 slightly better error message 2012-07-08 21:23:39 +02:00
rofl0r 364c785970 print everything to stderr, and fflush on PDEBUG 2012-07-08 04:18:42 +02:00
rofl0r 070051bb73 use macros for mutex stuff 2012-01-27 21:30:42 +01:00