Commit Graph

2064 Commits

Author SHA1 Message Date
Taylor R Campbell
137ae2e9cf Avoid undefined behaviour with the ctype(3) functions.
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.
2023-02-27 14:56:25 +00:00
Simon Kelley
5dc14b6e05 Replace dead link in dnsmasq.conf.example.
Thanks to Timo van Roermund for spotting this.
2023-02-02 20:24:24 +00:00
Simon Kelley
0427e37116 Replace dead link in dnsmasq.conf.example.
Thanks to Timo van Roermund for spotting this.
2023-02-02 20:20:13 +00:00
Dominik Derigs
e5e8cae1ca Add --no-ident option. 2023-01-23 22:48:01 +00:00
Simon Kelley
7f42ca8af8 Add acknowledgements to CHANGELOG for the 2.88 AWS efforts. 2023-01-14 11:12:17 +00:00
Simon Kelley
e4251eb13b Fix Changelog typos. 2023-01-14 11:01:10 +00:00
Simon Kelley
5083876910 Bump version in Debian changelog. 2023-01-13 22:03:33 +00:00
Simon Kelley
f172fdbb77 Fix bug which can break the invariants on the order of a hash chain.
If there are multiple cache records with the same name but different
F_REVERSE and/or F_IMMORTAL flags, the code added in fe9a134b could
concievable break the REVERSE-FORWARD-IMMORTAL order invariant.

Reproducing this is damn near impossible, but it is responsible
for rare and otherwise inexplicable reversion between 2.87 and 2.88
which manifests itself as a cache internal error. All observed
cases have depended on DNSSEC being enabled, but the bug could in
theory manifest itself without DNSSEC

Thanks to Timo van Roermund for reporting the bug and huge
efforts to isolate it.
2023-01-13 21:12:53 +00:00
Simon Kelley
3822825e54 Fix cosmetic big in dump_cache_entry() 2023-01-04 23:10:07 +00:00
Simon Kelley
1da54210fc Log all cache internal errors. 2023-01-02 22:17:57 +00:00
Simon Kelley
43a2a66531 If we hit a cache internal error, log the entry we failed to remove.
This is code which should never run, but if it does,
we now log information useful for debugging.
2022-12-22 23:19:05 +00:00
Simon Kelley
e6841ea2e0 Add posix-timezone and tzdb-timezone DHCPv6 options.
They are already in place for DHCPv4.
2022-12-04 22:00:54 +00:00
Simon Kelley
e939b45c9f Handle malformed DNS replies better.
If we detect that that reply from usptream is malformed,
transform it into a SERVFAIL reply before sending to the
original requestor.
2022-11-26 22:19:29 +00:00
Brad Smith
e3068ed111 Fix warning in cache.c 2022-11-26 21:48:17 +00:00
Dominik Derigs
efbf80be58 Make max staleness of stale cache entries configurable and default to one day. 2022-11-26 21:18:34 +00:00
Petr Menšík
022ad63f0c Fix use-after-free in mark_servers() 2022-11-26 18:49:21 +00:00
Petr Menšík
02f8754339 fixup! Handle DS records for unsupported crypto algorithms. 2022-11-22 22:51:11 +00:00
Simon Kelley
142456cfd0 Merge i18n strings. 2022-11-21 16:56:51 +00:00
Simon Kelley
207ce40db2 Add /etc/hosts gotcha to man page section for --dhcp-hosts. 2022-11-21 16:53:56 +00:00
Simon Kelley
881eaa4dbc Optimise readng large number --server options at start up.
When re-reading upstream servers from /etc/resolv.conf or other
sources that can change dnsmasq tries to avoid memory fragmentation by
re-using existing records that are being re-read unchanged. This
involves seaching all the server records for each new one installed.
During startup this search is pointless, and can cause long start
times with thousands of --server options because the work needed is
O(n^2). Handle this case more intelligently.  Thanks to Ye Zhou for
spotting the problem and an initial patch.
2022-11-21 16:40:53 +00:00
Matthias Andree
d6d7527c95 Fix CHANGELOG typos. 2022-11-18 09:10:32 +00:00
Conrad Kostecki
11b4be2036 Update german translation for release 2.88. 2022-11-17 20:00:42 +00:00
Simon Kelley
3e306c1202 Fix SEGV on --local= added by immediately previous commit. 2022-11-17 19:51:15 +00:00
Simon Kelley
7f227a83f2 Fix struct hostinfo free code and BSD compile.
The code added in6 c596f1cc1d92b2b90ef5ce043ace314eefa868b
fails to free the returned datastructures from gethostinfo()
because sdetails.hostinfo is used to loop through the addresses
and ends up NULL. In some libc implementations this results
in a SEGV when freeaddrinfo() is called.

Also fix FTBFS under BSD. Thanks to Johnny S. Lee for the bug report.
2022-11-17 13:16:55 +00:00
Simon Kelley
9ed3ee67ec Handle DS records for unsupported crypto algorithms correctly.
Such a DS, as long as it is validated, should allow answers
in the domain is attests to be returned as unvalidated, and not
as a validation error.
2022-11-16 16:49:30 +00:00
Simon Kelley
1f9215f5f9 Fix GOST signature algorithms for DNSSEC validation.
Use CryptoPro version of the hash function.
Handle the little-endian wire format of key data.
Get the wire order of S and R correct.

Note that Nettle version 3.6 or later is required for GOST support.
2022-11-16 15:57:31 +00:00
Simon Kelley
f52cfdd8c3 Handle known DNSSEC signature algorithms which are not supported.
This fixes a confusion if certain algorithms are not supported
because the version is the crypto library is too old.  The validation
should be treated the same as for a completely unknown algorithm,
(ie return unverified answer) and not as a validation failure
(ie return SERVFAIL).

The algorithems affected are GOST and ED448.
2022-11-13 15:55:09 +00:00
Simon Kelley
2fc904111d Fix --server=/domain/# 2022-11-07 23:24:31 +00:00
Simon Kelley
262dadf50e Fix --server with multiple domains. 2022-11-07 23:14:30 +00:00
Simon Kelley
6c596f1cc1 Make specifying nameservers by name work for DBus API. 2022-11-07 23:00:34 +00:00
Simon Kelley
dafa16c400 Call freeaddrinfo() in domain_rev[46]() 2022-11-07 22:01:28 +00:00
Simon Kelley
1db9943c68 Extend specifying DNS servers by domain-name to --rev-server
Also Dbus SetDomainServers method.

Revert getaddrinfo hints.ai_socktype to SOCK_DGRAM to eliminate
duplicating every address three times for DGRAM, STREAM and RAW
in the results.
2022-11-06 21:10:19 +00:00
Simon Kelley
5b868c213b Fix breakage of --local=/domain.name/1.2.3.4 in immediately previous commit. 2022-11-06 20:18:27 +00:00
Dominik Derigs
2d8905dafd Allow domain names as well is IP addresses in --server options. 2022-11-05 11:49:52 +00:00
Simon Kelley
9002108551 Bump Debian version and close bug. 2022-11-02 22:18:35 +00:00
Simon Kelley
d3c21c596e Reconcile "names" and "address" counts when reading hostfiles. 2022-10-30 15:40:20 +00:00
Simon Kelley
34fac952b6 Inotify: make "flushed" log message more understandable.
Saying we've "flushed x outdated entries" is confusing, since
the count is the total number of entries in the modified file,
most of which are going	to get added straight back when	the file
is re-read.

The log now looks like

dnsmasq: inotify: /tmp/dir/1 (new or modified)
dnsmasq: inotify: flushed 1 addresses read from /tmp/dir/1
dnsmasq: read /tmp/dir/1 - 2 addresses

which hopefully make it more obvious that /tmp/dir/1 contained one
address before, and now contains two.
2022-10-27 13:24:37 +01:00
Dominik Derigs
92c32e0bac Do not (try to) re-read deleted files inside a --hostsdir. 2022-10-27 12:36:38 +01:00
Simon Kelley
1bcad67806 Fix in dhcpv4 rapid-commit code.
1) Cosmetic: don't log the tags twice.

2) Functional. If a host has an old lease for a different address,
   the rapid-commit will appear to work, but the old lease will
   not be removed and the new lease will not be recorded, so
   the client and server will have conflicting state, leading to
   problems later.
2022-10-27 12:04:58 +01:00
Simon Kelley
fe9a134baf Add --no-round-robin option. 2022-10-18 16:06:48 +01:00
Simon Kelley
930428fb97 Fix loss of DNS servers on config reload.
A bug, introduced in 2.87, which could result in DNS
servers being removed from the configuration when reloading
server configuration from DBus, or re-reading /etc/resolv.conf
Only servers from the same source should be replaced, but some
servers from other sources (ie hard coded or another dynamic source)
could mysteriously disappear.
2022-10-17 21:15:43 +01:00
Dominik Derigs
936be022d9 Handle multiple addresses when removing duplicates in host files. 2022-10-16 22:30:08 +01:00
Dominik Derigs
0017dd74d5 Enhance --hostdir so that records are automatically removed when re-reading.
Initial patch from Dominik Derigs, re-written by Simon Kelley.
2022-10-16 22:10:48 +01:00
Dominik Derigs
0ba25a0512 Improve logging of DNS record source from --hostsdir files.
Patch author Dominik Derigs <dl6er@dl6er.de> with subsequent bugfixes
and tweaks from Simon Kelley.
2022-10-16 21:14:16 +01:00
Simon Kelley
a176cf1bc3 Move fast-dns-retry and use-stale-cache writeups in the CHANGELOG.
These are 2.88 changes, but the branch merge put them unde 2.87.
2022-10-14 11:46:13 +01:00
Simon Kelley
fdd9a96a8c Merge branch 'aws' 2022-10-13 15:37:52 +01:00
Simon Kelley
b87d7aa041 Fix bug in --dynamic-host when interface has /16 IPv4 address. 2022-10-13 15:02:54 +01:00
Temuri Doghonadze
f753e7eba6 Add Georgian translation. 2022-10-13 14:33:01 +01:00
Simon Kelley
78a5a21655 Fix Debian changelog date Fubar. 2022-09-25 23:55:09 +01:00
Simon Kelley
a5cbe6d112 Add ClearMetrics Dbus method. 2022-09-16 12:58:41 +01:00