summaryrefslogtreecommitdiff
path: root/src/loop.c
Commit message (Collapse)AuthorAgeFilesLines
* Bump copyrights to 2023.Simon Kelley2023-04-051-1/+1
|
* Avoid undefined behaviour with the ctype(3) functions.Taylor R Campbell2023-02-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As defined in the C standard: In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF. If the argument has any other value, the behavior is undefined. This is because they're designed to work with the int values returned by getc or fgetc; they need extra work to handle a char value. If EOF is -1 (as it almost always is), with 8-bit bytes, the allowed inputs to the ctype(3) functions are: {-1, 0, 1, 2, 3, ..., 255}. However, on platforms where char is signed, such as x86 with the usual ABI, code like char *arg = ...; ... isspace(*arg) ... may pass in values in the range: {-128, -127, -126, ..., -2, -1, 0, 1, ..., 127}. This has two problems: 1. Inputs in the set {-128, -127, -126, ..., -2} are forbidden. 2. The non-EOF byte 0xff is conflated with the value EOF = -1, so even though the input is not forbidden, it may give the wrong answer. Casting char to int first before passing the result to ctype(3) doesn't help: inputs like -128 are unchanged by this cast. It is necessary to cast char inputs to unsigned char first; you can then cast to int if you like but there's no need because the functions will always convert the argument to int by definition. So the above fragment needs to be: char *arg = ...; ... isspace((unsigned char)*arg) ... This patch inserts unsigned char casts where necessary, and changes int casts to unsigned char casts where the input is char. I left alone int casts where the input is unsigned char already -- they're not immediately harmful, although they would have the effect of suppressing some compiler warnings if the input is ever changed to be char instead of unsigned char, so it might be better to remove those casts too. I also left alone calls where the input is int to begin with because it came from getc; casting to unsigned char here would be wrong, of course.
* Bump copyright to 2022.Simon Kelley2022-01-241-1/+1
|
* Rationalise --server parsing and datastructure building.Simon Kelley2021-06-251-2/+4
| | | | Use add_update_server for everything.
* Major rewrite of the DNS server and domain handling code.Simon Kelley2021-06-081-11/+11
| | | | | | | | | | | | | | | | | | | | | This should be largely transparent, but it drastically improves performance and reduces memory foot-print when configuring large numbers domains of the form local=/adserver.com/ or local=/adserver.com/# Lookup times now grow as log-to-base-2 of the number of domains, rather than greater than linearly, as before. The change makes multiple addresses associated with a domain work address=/example.com/1.2.3.4 address=/example.com/5.6.7.8 It also handles multiple upstream servers for a domain better; using the same try/retry alogrithms as non domain-specific servers. This also applies to DNSSEC-generated queries. Finally, some of the oldest and gnarliest code in dnsmasq has had a significant clean-up. It's far from perfect, but it _is_ better.
* Use random source ports where possible if source addresses/interfaces in use.Simon Kelley2021-03-171-13/+7
| | | | | | | | | | | | | | | | | | | | | | | | CVE-2021-3448 applies. It's possible to specify the source address or interface to be used when contacting upstream nameservers: server=8.8.8.8@1.2.3.4 or server=8.8.8.8@1.2.3.4#66 or server=8.8.8.8@eth0, and all of these have, until now, used a single socket, bound to a fixed port. This was originally done to allow an error (non-existent interface, or non-local address) to be detected at start-up. This means that any upstream servers specified in such a way don't use random source ports, and are more susceptible to cache-poisoning attacks. We now use random ports where possible, even when the source is specified, so server=8.8.8.8@1.2.3.4 or server=8.8.8.8@eth0 will use random source ports. server=8.8.8.8@1.2.3.4#66 or any use of --query-port will use the explicitly configured port, and should only be done with understanding of the security implications. Note that this change changes non-existing interface, or non-local source address errors from fatal to run-time. The error will be logged and communiction with the server not possible.
* Bump copyright notices for 2021. Happy New Year!Simon Kelley2021-01-241-1/+1
|
* Update copyrights to 2020.Simon Kelley2020-01-051-1/+1
|
* Update copyrights to 2018.Simon Kelley2018-01-011-1/+1
|
* Bump year in copyrights.Simon Kelley2017-06-241-1/+1
|
* Update copyright notices. Happy new year!Simon Kelley2016-01-061-1/+1
|
* Fix boilerplate code for re-running system calls on EINTR and EAGAIN etc.Simon Kelley2015-03-111-2/+3
| | | | | | The nasty code with static variable in retry_send() which avoids looping forever needs to be called on success of the syscall, to reset the static variable.
* Update copyrights for dawn of 2015.Simon Kelley2015-01-311-1/+1
|
* Add --dns-loop-detect feature.Simon Kelley2014-07-291-0/+116