Commit Graph

1732 Commits (master)

Author SHA1 Message Date
Anton Khirnov 3bb14e0440 Allow multiple Bind directives.
Try all the addresses specified with Bind in order. This is necessary
e.g. for maintaining IPv4+6 connectivity while still being restricted to
one interface.
2020-10-19 20:08:31 +01:00
Anton Khirnov 2b49ef0e0f sock: add missing format specifier to log_message() 2020-10-19 20:08:31 +01:00
rofl0r f7c616d2b9 log.c: fix format string args 2020-10-19 20:08:31 +01:00
rofl0r cc0a7eb9a2 html-error: move common.h inclusion back to top
this seems to cause an implicit declaration of snprintf() thanks to
feature test macro hell.
2020-10-19 20:08:31 +01:00
rofl0r e20aa221ff conf: move inclusion of common.h back to the start
otherwise the feature-test-macros won't kick in as they should.

should fix #329
2020-10-01 15:25:35 +01:00
rofl0r 8d27503cc3 acl: fix regression using ipv6 with netmask
introduced in 0ad8904b40

closes #327
2020-09-30 19:23:34 +01:00
rofl0r 3950a606a4 conf: only treat space and tab as whitespace
other characters in the [[:space:]] set can't possibly be encountered,
and this speeds up parsing by approximately 10%.
2020-09-30 05:31:56 +01:00
rofl0r a8944b93e7 conf: use [0-9] instead of [[:digit:]] for shorter re strings 2020-09-30 05:28:00 +01:00
rofl0r 960972865c print linenumber from all conf-emitted warnings 2020-09-30 05:21:26 +01:00
rofl0r f55c46eb39 log: print timestamps with millisecond precision
this allows easier time measurements for benchmarks.
2020-09-30 05:20:09 +01:00
rofl0r 10494cab8c change loglevel of "Not running as root" message to INFO
there's no reason to display this as warning.
2020-09-30 05:19:16 +01:00
rofl0r 4f1a1663ff conf: remove bogus support for hex literals
the INT regex macro supported a 0x prefix (used e.g. for port numbers),
however following that, only digits were accepted, and not the full
range of hexdigits. it's unlikely this was used, so remove it.

note that the () expression is kept, so we don't have to adjust match
number indices all over the place.
2020-09-30 05:14:57 +01:00
rofl0r 35c8edcf73 speed up build by only including regex.h where needed 2020-09-30 05:13:45 +01:00
rofl0r 7c664ad0b2 Release 1.11.0-rc1 2020-09-27 16:22:21 +01:00
rofl0r 8594e9b8cc add conf-tokens.gperf to EXTRA_DIST
otherwise it will be missing in `make dist`-generated tarballs.
2020-09-27 15:55:23 +01:00
rofl0r 094db9d670 version.sh: relax regex for release tag detection
this allows to use tag names with a custom suffix too.
2020-09-27 15:44:50 +01:00
rofl0r 4dfac863a5 version.sh: replace -g with -git-
git describe prefixes the sha1 commit hash with -g, which is exactly what
we're after. this change gets rid of the confusing "g" in the commit hash
and allows tag names that include "-".
2020-09-27 15:41:54 +01:00
rofl0r c74fe57262 transparent: workaround old glibc bug on RHEL7
it's been reported[0] that RHEL7 fails to properly set the length
parameter of the getsockname() call to the length of the required
struct sockaddr type, and always returns the length passed if it
is big enough.

the SOCKADDR_UNION_* macros originate from my microsocks[1] project,
and facilitate handling of the sockaddr mess without nasty casts.

[0]: https://github.com/tinyproxy/tinyproxy/issues/45#issuecomment-694594990
[1]: https://github.com/rofl0r/microsocks
2020-09-18 12:12:14 +01:00
rofl0r d4ef2cfa62 child_kill_children(): use method that actually works
it turned out that close()ing an fd behind the back of a thread
doesn't actually cause blocking operations to get a read/write event,
because the fd will stay valid to in-progress operations.
2020-09-17 21:24:45 +01:00
rofl0r da1bc1425d tune error messages to show select or poll depending on what is used 2020-09-17 21:03:51 +01:00
rofl0r 22e4898519 add autoconf test and fallback code for systems without gperf 2020-09-16 23:04:12 +01:00
rofl0r 45b238fc6f main: print error when config_init() fails 2020-09-16 21:01:02 +01:00
rofl0r 45323584a0 speed up big config parsing by 2x using gperf 2020-09-16 21:01:02 +01:00
rofl0r caeab31fca conf.c: simplify the huge IPV6 regex
even though the existing IPV6 regex caught (almost?) all invalid
ipv6 addresses, it did so with a huge performance penalty.
parsing a file with 32K allow or deny statement took 30 secs in
a test setup, after this change less than 3.

the new regex is sufficient to recognize all valid ipv6 addresses,
and hands down the responsibility to detect corner cases to the
system's inet_pton() function, which is e.g. called from insert_acl(),
which now causes a warning to be printed in the log if a seemingly
valid address is in fact invalid.

the new regex has been tested with 486 testcases from
http://download.dartware.com/thirdparty/test-ipv6-regex.pl
and accepts all valid ones and rejects most of the invalid ones.

note that the IPV4 regex already did a similar thing and checked only
whether the ip looks like [0-9]+.[0-9]+.[0-9]+.[0-9]+ without pedantry.
2020-09-16 21:01:02 +01:00
rofl0r 0ad8904b40 acl.c: detect invalid ipv6 string 2020-09-16 21:00:50 +01:00
rofl0r 99ed66cbc4 conf.c: warn when encountering invalid address 2020-09-16 21:00:50 +01:00
rofl0r 880a8b0ab6 conf: use cpp stringification for STDCONF macro 2020-09-16 21:00:04 +01:00
rofl0r 551e914d24 conf: merge upstream/upstream_none into single regex/handler 2020-09-16 21:00:04 +01:00
rofl0r bad36cd9cd move config reload message to reload_config()
move it to before disabling logging, so a message with the correct
timestamp is printed if logging was already enabled.
also add a message when loading finished, so one can see from the
timestamp how long it took.

note that this only works on a real config reload triggered by
SIGHUP/SIGUSR1, because on startup we don't know yet where to log to.
2020-09-16 21:00:04 +01:00
rofl0r 683a354196 remove vector remains 2020-09-16 02:39:09 +01:00
rofl0r 06c96761d5 log_message_storage: use sblist 2020-09-16 02:39:09 +01:00
rofl0r 54ae2d2a19 tests: add some AddHeader directives 2020-09-16 02:39:09 +01:00
rofl0r e843519fb8 listen_addrs: use sblist 2020-09-16 02:39:09 +01:00
rofl0r a5381223df basicauth: use sblist 2020-09-16 02:39:09 +01:00
rofl0r 487f2aba47 connect_ports: use sblist 2020-09-16 02:39:09 +01:00
rofl0r e929e81a55 add_header: use sblist
note that the old code inserted added headers at the beginning of the
list, reasoning unknown. this seems counter-intuitive as the headers
would end up in the request in the reverse order they were added,
but this was irrelevant, as the headers were originally first put
into the hashmap hashofheaders before sending it to the client.
since the hashmap didn't preserve ordering, the headers would appear
in random order anyway.
2020-09-16 02:39:09 +01:00
rofl0r 7d33fc8e8a listen_fds: use sblist 2020-09-16 01:05:58 +01:00
rofl0r a5890b621b run_tests_valgrind: use tougher valgrind settings 2020-09-15 23:39:04 +01:00
rofl0r 2037bc64f5 free a mem leak by statically allocating global statsbuf 2020-09-15 23:28:33 +01:00
rofl0r d453a4c2a4 main: include loop header 2020-09-15 23:20:14 +01:00
rofl0r 192f8194e1 free() loop records too 2020-09-15 23:12:00 +01:00
rofl0r bd92446184 use poll() where available 2020-09-15 23:12:00 +01:00
rofl0r 10cdee3bc5 prepare transition to poll()
usage of select() is inefficient (because a huge fd_set array has to
be initialized on each call) and insecure (because an fd >= FD_SETSIZE
will cause out-of-bounds accesses using the FD_*SET macros, and a system
can be set up to allow more than that number of fds using ulimit).
for the moment we prepared a poll-like wrapper that still runs select()
to test for regressions, and so we have fallback code for systems without
poll().
2020-09-15 23:12:00 +01:00
rofl0r 0c8275a90e refactor conns.[ch], put conn_s into child struct
this allows to access the conn member from the main thread handling
the childs, plus simplifies the code.
2020-09-15 23:12:00 +01:00
rofl0r 5779ba8697 hsearch: add seed to prevent another CVE-2012-3505 instance 2020-09-15 23:12:00 +01:00
rofl0r 155bfbbe87 replace leftover users of hashmap with htab
also fixes a bug where the ErrorFile directive would create a
new hashmap on every added item, effectively allowing only
the use of the last specified errornumber, and producing memory
leaks on each config reload.
2020-09-15 23:12:00 +01:00
rofl0r 34a8b28414 save headers in an ordered dictionary
due to the usage of a hashmap to store headers, when relaying them
to the other side the order was not prevented.
even though correct from a standards point-of-view, this caused
issues with various programs, and it allows to fingerprint the use
of tinyproxy.

to implement this, i imported the MIT-licensed hsearch.[ch] from
https://github.com/rofl0r/htab which was originally taken from
musl libc. it's a simple and efficient hashtable implementation
with far better performance characteristic than the one previously
used by tinyproxy. additionally it has an API much more well-suited
for this purpose.

orderedmap.[ch] was implemented from scratch to address this issue.
behind the scenes it uses an sblist to store string values, and a htab
to store keys and the indices into the sblist.
this allows us to iterate linearly over the sblist and then find the
corresponding key in the hash table, so the headers can be reproduced
in the order they were received.

closes #73
2020-09-15 23:11:59 +01:00
rofl0r 9d5ee85c3e fix free()ing of config items
- we need to free the config after it has been succesfully loaded,
  not unconditionally before reloading.
- we also need to free them before exiting from the main program
  to have clean valgrind output.
2020-09-15 23:11:59 +01:00
rofl0r 372d7ff824 shutdown: free children from right place 2020-09-15 22:32:42 +01:00
rofl0r 2f3a3828ac Revert "childs.c: fix minor memory leak"
This reverts commit 6dd3806f7d.
2020-09-15 22:25:53 +01:00