dnsmasq.git
4 years agoGet compilation flags for libnftables from pkg-config.
Simon Kelley [Wed, 29 Sep 2021 22:24:52 +0000 (23:24 +0100)]
Get compilation flags for libnftables from pkg-config.

Omission spotted by Olaf Hering. Thanks.

4 years agodnsmasq_time: avoid signed integer overflow when HAVE_BROKEN_RTC
Matt Whitlock [Tue, 28 Sep 2021 00:44:25 +0000 (20:44 -0400)]
dnsmasq_time: avoid signed integer overflow when HAVE_BROKEN_RTC

The dnsmasq_time() function, in the case of HAVE_BROKEN_RTC, was calling
times() to read the number of ticks "elapsed since an arbitrary point in
the past" and then dividing that by sysconf(_SC_CLK_TCK) to compute the
number of seconds elapsed since that arbitrary instant. This works fine
until the number of ticks exceeds 2^31, beyond which time the function
would begin erroneously returning negative times. On my system this
happens after approximately 248 days of uptime. A symptom is that
dnsmasq no longer populates the resolver cache with DHCP-derived names
at startup, as the inserted cache entries immediately expire due to
having negative expiration times that cause is_expired() to return true
when called with now==0.

This commit replaces the archaic implementation of dnsmasq_time() with a
call to the POSIX-standardized clock_gettime(CLOCK_MONOTONIC), thereby
eliminating the need to convert manually from ticks to seconds. The new
implementation will yield correct results until the system uptime
exceeds approximately 68 years.

Signed-off-by: Matt Whitlock <dnsmasq@mattwhitlock.name>
4 years agoFix FTBFS when CONNTRACK and UBUS but not DNSSEC compile options selected.
Simon Kelley [Tue, 28 Sep 2021 22:42:15 +0000 (23:42 +0100)]
Fix FTBFS when CONNTRACK and UBUS but not DNSSEC compile options selected.

4 years agoBuild Debian binaries with NFTset support.
Simon Kelley [Mon, 27 Sep 2021 22:14:36 +0000 (23:14 +0100)]
Build Debian binaries with NFTset support.

4 years agoFix confusion in DNS retries and --strict-order.
Simon Kelley [Mon, 27 Sep 2021 21:37:02 +0000 (22:37 +0100)]
Fix confusion in DNS retries and --strict-order.

Behaviour to stop infinite loops when all servers return REFUSED
was wrongly activated on client retries, resulting in
incorrect REFUSED replies to client retries.

Thanks to Johannes Stezenbach for finding the problem.

4 years agoAdd --nftset option, like --ipset but for the newer nftables. v2.87test2
Simon Kelley [Mon, 27 Sep 2021 20:31:20 +0000 (21:31 +0100)]
Add --nftset option, like --ipset but for the newer nftables.

Thanks to Chen Zhenge for the original patch, which I've
reworked. Any bugs down to SRK.

4 years agoMake --rebind-domain-ok work with IDN.
Simon Kelley [Fri, 24 Sep 2021 14:25:05 +0000 (15:25 +0100)]
Make --rebind-domain-ok work with IDN.

4 years agomanpage: clarify tags: semantics for --dhcp-host
Paul Fertser [Fri, 24 Sep 2021 11:57:38 +0000 (14:57 +0300)]
manpage: clarify tags: semantics for --dhcp-host

Mention that several tags can be specified and instruct the user that
some other match must still be provided for the directive to have any
effect.

4 years agoImprove last patch by splitting the previously combined if
Dominik Derigs [Thu, 23 Sep 2021 19:12:40 +0000 (21:12 +0200)]
Improve last patch by splitting the previously combined if

Signed-off-by: DL6ER <dl6er@dl6er.de>
(also cosmetic change to logging for improved translation from
Matthias Andree <matthias.andree@gmx.de>)

4 years agoCorrecly warn if dynamic directory is actually no directory
Dominik Derigs [Wed, 22 Sep 2021 13:32:59 +0000 (15:32 +0200)]
Correcly warn if dynamic directory is actually no directory

Signed-off-by: DL6ER <dl6er@dl6er.de>
4 years agoFix --address=/#/...... which was lost in 2.86
Simon Kelley [Thu, 23 Sep 2021 09:54:46 +0000 (10:54 +0100)]
Fix --address=/#/...... which was lost in 2.86

A victim of the domain-search rewrite. Apologies.

4 years agoCheck if allocation of 66573 bytes succeeded before accessing the memory to avoid...
Dominik DL6ER [Sat, 18 Sep 2021 14:05:34 +0000 (16:05 +0200)]
Check if allocation of 66573 bytes succeeded before accessing the memory to avoid crash in busy times

Signed-off-by: DL6ER <dl6er@dl6er.de>
4 years agoOptimize inserting records into server list.
hev [Sun, 19 Sep 2021 10:56:08 +0000 (18:56 +0800)]
Optimize inserting records into server list.

Signed-off-by: hev <r@hev.cc>
4 years agoThinko in immediately previous commit.
Simon Kelley [Mon, 20 Sep 2021 18:44:56 +0000 (19:44 +0100)]
Thinko in immediately previous commit.

4 years agoAdd support for arbitrary prefix lengths in --rev-server and --domain=....,local
Simon Kelley [Sun, 19 Sep 2021 23:05:42 +0000 (00:05 +0100)]
Add support for arbitrary prefix lengths in --rev-server and --domain=....,local

Previously, the prefix was limited to [8,16,24,32] for IPv4 and
to multiples of 4 for IPv6. This patch also makes the prefix-length optional
for --rev-server.

Inspired by a patch from DL6ER <dl6er@dl6er.de>, but completely
re-written by srk. All bugs are his.

4 years agoFix confusion is server=/domain/# combined with server|address=/domain/....
Simon Kelley [Sat, 18 Sep 2021 22:01:12 +0000 (23:01 +0100)]
Fix confusion is server=/domain/# combined with server|address=/domain/....

The 2.86 domain matching rewrite failed to take into account the possibilty that

server=/example.com/#

could be combined with, for example

address=/example.com/1.2.3.4

resulting in the struct server datastructure for the former getting passed
to forward_query(), rapidly followed by a SEGV.

This fix makes server=/example.com/# a fully fledged member of the
priority list, which is now  IPv6 addr, IPv4 addr, all zero return,
resolvconf servers, upstream servers, no-data return

Thanks to dl6er@dl6er.de for finding and characterising the bug.

4 years agoFix coverity issues in dnssec.c
Petr Menšík [Fri, 3 Sep 2021 20:51:36 +0000 (22:51 +0200)]
Fix coverity issues in dnssec.c

Error: CHECKED_RETURN (CWE-252): [#def26]
dnsmasq-2.86rc3/src/dnssec.c:727: check_return: Calling "extract_name" without checking return value (as is done elsewhere 9 out of 10 times).
dnsmasq-2.86rc3/src/dnssec.c:459: example_checked: Example 1: "extract_name(header, plen, &p, keyname, 1, 0)" has its value checked in "extract_name(header, plen, &p, keyname, 1, 0)".
dnsmasq-2.86rc3/src/dnssec.c:269: example_checked: Example 2: "extract_name(header, plen, &state->ip, state->buff, 1, 0)" has its value checked in "extract_name(header, plen, &state->ip, state->buff, 1, 0)".
dnsmasq-2.86rc3/src/dnssec.c:569: example_checked: Example 3: "extract_name(header, plen, &p, keyname, 1, 0)" has its value checked in "extract_name(header, plen, &p, keyname, 1, 0)".
dnsmasq-2.86rc3/src/rfc1035.c:648: example_checked: Example 4: "extract_name(header, qlen, &p1, name, 1, 0)" has its value checked in "extract_name(header, qlen, &p1, name, 1, 0)".
dnsmasq-2.86rc3/src/rfc1035.c:787: example_checked: Example 5: "extract_name(header, qlen, &p1, name, 1, 0)" has its value checked in "extract_name(header, qlen, &p1, name, 1, 0)".
 #  725|         /* namebuff used for workspace above, restore to leave unchanged on exit */
 #  726|         p = (unsigned char*)(rrset[0]);
 #  727|->       extract_name(header, plen, &p, name, 1, 0);
 #  728|
 #  729|         if (key)

Error: CHECKED_RETURN (CWE-252): [#def27]
dnsmasq-2.86rc3/src/dnssec.c:1020: check_return: Calling "extract_name" without checking return value (as is done elsewhere 7 out of 8 times).
dnsmasq-2.86rc3/src/auth.c:140: example_checked: Example 1: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/dnssec.c:771: example_checked: Example 2: "extract_name(header, plen, &p, name, 1, 4)" has its value checked in "extract_name(header, plen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/hash-questions.c:57: example_checked: Example 3: "extract_name(header, plen, &p, name, 1, 4)" has its value checked in "extract_name(header, plen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/rfc1035.c:1028: example_checked: Example 4: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/rfc1035.c:1438: example_checked: Example 5: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
 # 1018|
 # 1019|     p = (unsigned char *)(header+1);
 # 1020|->   extract_name(header, plen, &p, name, 1, 4);
 # 1021|     p += 4; /* qtype, qclass */
 # 1022|

4 years agoFix coverity detected issues in dnsmasq.c
Petr Menšík [Fri, 3 Sep 2021 20:45:29 +0000 (22:45 +0200)]
Fix coverity detected issues in dnsmasq.c

Error: DEADCODE (CWE-561): [#def12]
dnsmasq-2.86rc3/src/dnsmasq.c:37: assignment: Assigning: "bind_fallback" = "0".
dnsmasq-2.86rc3/src/dnsmasq.c:927: const: At condition "bind_fallback", the value of "bind_fallback" must be equal to 0.
dnsmasq-2.86rc3/src/dnsmasq.c:927: dead_error_condition: The condition "bind_fallback" cannot be true.
dnsmasq-2.86rc3/src/dnsmasq.c:928: dead_error_line: Execution cannot reach this statement: "my_syslog(4, "setting --bin...".
dnsmasq-2.86rc3/src/dnsmasq.c:928: effectively_constant: Local variable "bind_fallback" is assigned only once, to a constant value, making it effectively constant throughout its scope. If this is not the intent, examine the logic to see if there is a missing assignment that would make "bind_fallback" not remain constant.
 #  926|
 #  927|     if (bind_fallback)
 #  928|->     my_syslog(LOG_WARNING, _("setting --bind-interfaces option because of OS limitations"));
 #  929|
 #  930|     if (option_bool(OPT_NOWILD))

Error: REVERSE_NEGATIVE (CWE-191): [#def13]
dnsmasq-2.86rc3/src/dnsmasq.c:383: negative_sink_in_call: Passing "dnsmasq_daemon->pxefd" to a parameter that cannot be negative.
dnsmasq-2.86rc3/src/dnsmasq.c:1086: check_after_sink: You might be using variable "dnsmasq_daemon->pxefd" before verifying that it is >= 0.
 # 1084|    {
 # 1085|      poll_listen(daemon->dhcpfd, POLLIN);
 # 1086|->    if (daemon->pxefd != -1)
 # 1087|        poll_listen(daemon->pxefd, POLLIN);
 # 1088|    }

Error: CHECKED_RETURN (CWE-252): [#def18]
dnsmasq-2.86rc3/src/dnsmasq.c:1582: check_return: Calling "fcntl(dnsmasq_daemon->helperfd, 4, i & 0xfffffffffffff7ff)" without checking return value. This library function may fail and return an error code.
 # 1580|        /* block in writes until all done */
 # 1581|        if ((i = fcntl(daemon->helperfd, F_GETFL)) != -1)
 # 1582|->        fcntl(daemon->helperfd, F_SETFL, i & ~O_NONBLOCK);
 # 1583|        do {
 # 1584|          helper_write();

Error: CHECKED_RETURN (CWE-252): [#def22]
dnsmasq-2.86rc3/src/dnsmasq.c:1991: check_return: Calling "fcntl(confd, 4, flags & 0xfffffffffffff7ff)" without checking return value. This library function may fail and return an error code.
 # 1989|     Reset that here. */
 # 1990|          if ((flags = fcntl(confd, F_GETFL, 0)) != -1)
 # 1991|->  fcntl(confd, F_SETFL, flags & ~O_NONBLOCK);
 # 1992|
 # 1993|          buff = tcp_request(confd, now, &tcp_addr, netmask, auth_dns);

Error: CHECKED_RETURN (CWE-252): [#def26]
dnsmasq-2.86rc3/src/dnssec.c:727: check_return: Calling "extract_name" without checking return value (as is done elsewhere 9 out of 10 times).
dnsmasq-2.86rc3/src/dnssec.c:459: example_checked: Example 1: "extract_name(header, plen, &p, keyname, 1, 0)" has its value checked in "extract_name(header, plen, &p, keyname, 1, 0)".
dnsmasq-2.86rc3/src/dnssec.c:269: example_checked: Example 2: "extract_name(header, plen, &state->ip, state->buff, 1, 0)" has its value checked in "extract_name(header, plen, &state->ip, state->buff, 1, 0)".
dnsmasq-2.86rc3/src/dnssec.c:569: example_checked: Example 3: "extract_name(header, plen, &p, keyname, 1, 0)" has its value checked in "extract_name(header, plen, &p, keyname, 1, 0)".
dnsmasq-2.86rc3/src/rfc1035.c:648: example_checked: Example 4: "extract_name(header, qlen, &p1, name, 1, 0)" has its value checked in "extract_name(header, qlen, &p1, name, 1, 0)".
dnsmasq-2.86rc3/src/rfc1035.c:787: example_checked: Example 5: "extract_name(header, qlen, &p1, name, 1, 0)" has its value checked in "extract_name(header, qlen, &p1, name, 1, 0)".
 #  725|         /* namebuff used for workspace above, restore to leave unchanged on exit */
 #  726|         p = (unsigned char*)(rrset[0]);
 #  727|->       extract_name(header, plen, &p, name, 1, 0);
 #  728|
 #  729|         if (key)

Error: CHECKED_RETURN (CWE-252): [#def27]
dnsmasq-2.86rc3/src/dnssec.c:1020: check_return: Calling "extract_name" without checking return value (as is done elsewhere 7 out of 8 times).
dnsmasq-2.86rc3/src/auth.c:140: example_checked: Example 1: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/dnssec.c:771: example_checked: Example 2: "extract_name(header, plen, &p, name, 1, 4)" has its value checked in "extract_name(header, plen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/hash-questions.c:57: example_checked: Example 3: "extract_name(header, plen, &p, name, 1, 4)" has its value checked in "extract_name(header, plen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/rfc1035.c:1028: example_checked: Example 4: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
dnsmasq-2.86rc3/src/rfc1035.c:1438: example_checked: Example 5: "extract_name(header, qlen, &p, name, 1, 4)" has its value checked in "extract_name(header, qlen, &p, name, 1, 4)".
 # 1018|
 # 1019|     p = (unsigned char *)(header+1);
 # 1020|->   extract_name(header, plen, &p, name, 1, 4);
 # 1021|     p += 4; /* qtype, qclass */
 # 1022|

4 years agoFix coverity issues detected in domain-match.c
Petr Menšík [Sat, 11 Sep 2021 21:04:05 +0000 (22:04 +0100)]
Fix coverity issues detected in domain-match.c

Error: CHECKED_RETURN (CWE-252): [#def28]
dnsmasq-2.86rc3/src/domain-match.c:414: check_return: Calling "add_resource_record" without checking return value (as is done elsewhere 44 out of 46 times).
dnsmasq-2.86rc3/src/auth.c:214: example_checked: Example 1: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", intr->name)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", intr->name)".
dnsmasq-2.86rc3/src/auth.c:239: example_checked: Example 2: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", name)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", name)".
dnsmasq-2.86rc3/src/rfc1035.c:1463: example_checked: Example 3: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, crec_ttl(crecp, now), &nameoffset, 5, 1, "d", cname_target)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, crec_ttl(crecp, now), &nameoffset, 5, 1, "d", cname_target)".
dnsmasq-2.86rc3/src/rfc1035.c:1500: example_checked: Example 4: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, ttl, NULL, 16, t->class, "t", t->len, t->txt)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, ttl, NULL, 16, t->class, "t", t->len, t->txt)".
dnsmasq-2.86rc3/src/rfc1035.c:2021: example_checked: Example 5: "add_resource_record(header, limit, NULL, rec->offset, &ansp, crec_ttl(crecp, now), NULL, type, 1, ((crecp->flags & 0x80U) ? "4" : "6"), &crecp->addr)" has its value checked in "add_resource_record(header, limit, NULL, rec->offset, &ansp, crec_ttl(crecp, now), NULL, type, 1, ((crecp->flags & 0x80U) ? "4" : "6"), &crecp->addr)".
 #  412|
 #  413|    header->ancount = htons(ntohs(header->ancount) + 1);
 #  414|->  add_resource_record(header, limit, &trunc, sizeof(struct dns_header), &p, daemon->local_ttl, NULL, T_A, C_IN, "4", &addr);
 #  415|    log_query((flags | F_CONFIG | F_FORWARD) & ~F_IPV6, name, (union all_addr *)&addr, NULL);
 #  416|         }

Error: CHECKED_RETURN (CWE-252): [#def29]
dnsmasq-2.86rc3/src/domain-match.c:429: check_return: Calling "add_resource_record" without checking return value (as is done elsewhere 44 out of 46 times).
dnsmasq-2.86rc3/src/auth.c:214: example_checked: Example 1: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", intr->name)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", intr->name)".
dnsmasq-2.86rc3/src/auth.c:239: example_checked: Example 2: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", name)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, dnsmasq_daemon->auth_ttl, NULL, 12, 1, "d", name)".
dnsmasq-2.86rc3/src/rfc1035.c:1463: example_checked: Example 3: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, crec_ttl(crecp, now), &nameoffset, 5, 1, "d", cname_target)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, crec_ttl(crecp, now), &nameoffset, 5, 1, "d", cname_target)".
dnsmasq-2.86rc3/src/rfc1035.c:1500: example_checked: Example 4: "add_resource_record(header, limit, &trunc, nameoffset, &ansp, ttl, NULL, 16, t->class, "t", t->len, t->txt)" has its value checked in "add_resource_record(header, limit, &trunc, nameoffset, &ansp, ttl, NULL, 16, t->class, "t", t->len, t->txt)".
dnsmasq-2.86rc3/src/rfc1035.c:2021: example_checked: Example 5: "add_resource_record(header, limit, NULL, rec->offset, &ansp, crec_ttl(crecp, now), NULL, type, 1, ((crecp->flags & 0x80U) ? "4" : "6"), &crecp->addr)" has its value checked in "add_resource_record(header, limit, NULL, rec->offset, &ansp, crec_ttl(crecp, now), NULL, type, 1, ((crecp->flags & 0x80U) ? "4" : "6"), &crecp->addr)".
 #  427|
 #  428|    header->ancount = htons(ntohs(header->ancount) + 1);
 #  429|->  add_resource_record(header, limit, &trunc, sizeof(struct dns_header), &p, daemon->local_ttl, NULL, T_AAAA, C_IN, "6", &addr);
 #  430|    log_query((flags | F_CONFIG | F_FORWARD) & ~F_IPV4, name, (union all_addr *)&addr, NULL);
 #  431|         }

Error: NULL_RETURNS (CWE-476): [#def30]
dnsmasq-2.86rc3/src/domain-match.c:611: returned_null: "whine_malloc" returns "NULL" (checked 72 out of 76 times).
dnsmasq-2.86rc3/src/domain-match.c:611: var_assigned: Assigning: "alloc_domain" = "NULL" return value from "whine_malloc".
dnsmasq-2.86rc3/src/domain-match.c:620: dereference: Dereferencing a pointer that might be "NULL" "alloc_domain" when calling "hostname_isequal".
dnsmasq-2.86rc3/src/arp.c:88: example_checked: Example 1: "whine_malloc(48UL)" has its value checked in "arp = whine_malloc(48UL)".
dnsmasq-2.86rc3/src/blockdata.c:24: example_assign: Example 2: Assigning: "new" = return value from "whine_malloc(n * 48UL)".
dnsmasq-2.86rc3/src/blockdata.c:26: example_checked: Example 2 (cont.): "new" has its value checked in "new".
dnsmasq-2.86rc3/src/cache.c:1545: example_assign: Example 3: Assigning: "crecp" = return value from "whine_malloc(70UL)".
dnsmasq-2.86rc3/src/cache.c:1547: example_checked: Example 3 (cont.): "crecp" has its value checked in "crecp".
dnsmasq-2.86rc3/src/forward.c:1791: example_assign: Example 4: Assigning: "packet" = return value from "whine_malloc(66573UL)".
dnsmasq-2.86rc3/src/forward.c:1795: example_checked: Example 4 (cont.): "packet" has its value checked in "packet".
dnsmasq-2.86rc3/src/inotify.c:186: example_checked: Example 5: "whine_malloc(lendir + lenfile + 2UL)" has its value checked in "path = whine_malloc(lendir + lenfile + 2UL)".
 #  618|     if (flags & SERV_IS_LOCAL)
 #  619|       for (serv = daemon->servers; serv; serv = serv->next)
 #  620|->       if ((serv->flags & SERV_MARK) &&
 #  621|      hostname_isequal(alloc_domain, serv->domain))
 #  622|    break;

Error: RESOURCE_LEAK (CWE-772): [#def31] [important]
dnsmasq-2.86rc3/src/domain-match.c:611: alloc_fn: Storage is returned from allocation function "whine_malloc".
dnsmasq-2.86rc3/src/domain-match.c:611: var_assign: Assigning: "alloc_domain" = storage returned from "whine_malloc(1UL)".
dnsmasq-2.86rc3/src/domain-match.c:620: noescape: Resource "alloc_domain" is not freed or pointed-to in "hostname_isequal".
dnsmasq-2.86rc3/src/domain-match.c:646: leaked_storage: Variable "alloc_domain" going out of scope leaks the storage it points to.
 #  644|
 #  645|         if (!(serv = whine_malloc(size)))
 #  646|->  return 0;
 #  647|
 #  648|         if (flags & SERV_IS_LOCAL)

Error: NULL_RETURNS (CWE-476): [#def32]
dnsmasq-2.86rc3/src/domain-match.c:611: returned_null: "whine_malloc" returns "NULL" (checked 72 out of 76 times).
dnsmasq-2.86rc3/src/domain-match.c:611: var_assigned: Assigning: "alloc_domain" = "NULL" return value from "whine_malloc".
dnsmasq-2.86rc3/src/domain-match.c:674: dereference: Dereferencing a pointer that might be "NULL" "alloc_domain" when calling "strlen".
dnsmasq-2.86rc3/src/arp.c:88: example_checked: Example 1: "whine_malloc(48UL)" has its value checked in "arp = whine_malloc(48UL)".
dnsmasq-2.86rc3/src/blockdata.c:24: example_assign: Example 2: Assigning: "new" = return value from "whine_malloc(n * 48UL)".
dnsmasq-2.86rc3/src/blockdata.c:26: example_checked: Example 2 (cont.): "new" has its value checked in "new".
dnsmasq-2.86rc3/src/cache.c:1545: example_assign: Example 3: Assigning: "crecp" = return value from "whine_malloc(70UL)".
dnsmasq-2.86rc3/src/cache.c:1547: example_checked: Example 3 (cont.): "crecp" has its value checked in "crecp".
dnsmasq-2.86rc3/src/forward.c:1791: example_assign: Example 4: Assigning: "packet" = return value from "whine_malloc(66573UL)".
dnsmasq-2.86rc3/src/forward.c:1795: example_checked: Example 4 (cont.): "packet" has its value checked in "packet".
dnsmasq-2.86rc3/src/inotify.c:186: example_checked: Example 5: "whine_malloc(lendir + lenfile + 2UL)" has its value checked in "path = whine_malloc(lendir + lenfile + 2UL)".
 #  672|     serv->flags = flags;
 #  673|     serv->domain = alloc_domain;
 #  674|->   serv->domain_len = strlen(alloc_domain);
 #  675|
 #  676|     if (flags & SERV_4ADDR)

4 years agoFix coverity detected issues in cache.c
Simon Kelley [Sat, 11 Sep 2021 20:56:19 +0000 (21:56 +0100)]
Fix coverity detected issues in cache.c

Error: UNINIT (CWE-457): [#def27]
dnsmasq-2.86test7/src/cache.c:1193: var_decl: Declaring variable "lrec" without initializer.
dnsmasq-2.86test7/src/cache.c:1315: uninit_use_in_call: Using uninitialized value "lrec.ttd" when calling "make_non_terminals".
 # 1313|       {
 # 1314|         lrec.name.namep = txt->name;
 # 1315|->       make_non_terminals(&lrec);
 # 1316|       }
 # 1317|

Error: CLANG_WARNING: [#def29]
dnsmasq-2.86test7/src/cache.c:1552:15: warning[core.uninitialized.Assign]: Assigned value is garbage or undefined
 # 1550|    {
 # 1551|      crecp->flags = (source->flags | F_NAMEP) & ~(F_IPV4 | F_IPV6 | F_CNAME | F_SRV | F_DNSKEY | F_DS | F_REVERSE);
 # 1552|->    crecp->ttd = source->ttd;
 # 1553|      crecp->name.namep = name;
 # 1554|

4 years agoFix coverity detected issue in radv.c
Petr Menšík [Fri, 3 Sep 2021 17:29:23 +0000 (19:29 +0200)]
Fix coverity detected issue in radv.c

Error: NULL_RETURNS (CWE-476): [#def114]
dnsmasq-2.86test7/src/radv.c:748: returned_null: "expand" returns "NULL" (checked 10 out of 11 times).
dnsmasq-2.86test7/src/radv.c:748: var_assigned: Assigning: "p" = "NULL" return value from "expand".
dnsmasq-2.86test7/src/radv.c:749: dereference: Dereferencing a pointer that might be "NULL" "p" when calling "memset". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/outpacket.c:83: example_checked: Example 1: "expand(len)" has its value checked in "p = expand(len)".
dnsmasq-2.86test7/src/outpacket.c:109: example_checked: Example 2: "expand(1UL)" has its value checked in "p = expand(1UL)".
dnsmasq-2.86test7/src/radv.c:269: example_checked: Example 3: "expand(16UL)" has its value checked in "ra = expand(16UL)".
dnsmasq-2.86test7/src/radv.c:363: example_checked: Example 4: "expand(32UL)" has its value checked in "opt = expand(32UL)".
dnsmasq-2.86test7/src/radv.c:708: example_checked: Example 5: "expand(32UL)" has its value checked in "opt = expand(32UL)".
 #  747|         int len = (maclen + 9) >> 3;
 #  748|         unsigned char *p = expand(len << 3);
 #  749|->       memset(p, 0, len << 3);
 #  750|         *p++ = ICMP6_OPT_SOURCE_MAC;
 #  751|         *p++ = len;

Error: NULL_RETURNS (CWE-476): [#def115]
dnsmasq-2.86test7/src/radv.c:748: returned_null: "expand" returns "NULL" (checked 10 out of 11 times).
dnsmasq-2.86test7/src/radv.c:748: var_assigned: Assigning: "p" = "NULL" return value from "expand".
dnsmasq-2.86test7/src/radv.c:750: dereference: Incrementing a pointer which might be null: "p".
dnsmasq-2.86test7/src/outpacket.c:83: example_checked: Example 1: "expand(len)" has its value checked in "p = expand(len)".
dnsmasq-2.86test7/src/outpacket.c:109: example_checked: Example 2: "expand(1UL)" has its value checked in "p = expand(1UL)".
dnsmasq-2.86test7/src/radv.c:269: example_checked: Example 3: "expand(16UL)" has its value checked in "ra = expand(16UL)".
dnsmasq-2.86test7/src/radv.c:363: example_checked: Example 4: "expand(32UL)" has its value checked in "opt = expand(32UL)".
dnsmasq-2.86test7/src/radv.c:708: example_checked: Example 5: "expand(32UL)" has its value checked in "opt = expand(32UL)".
 #  748|         unsigned char *p = expand(len << 3);
 #  749|         memset(p, 0, len << 3);
 #  750|->       *p++ = ICMP6_OPT_SOURCE_MAC;
 #  751|         *p++ = len;
 #  752|         memcpy(p, mac, maclen);

4 years agoFix coverity detected issues in option.c
Petr Menšík [Fri, 3 Sep 2021 17:23:20 +0000 (19:23 +0200)]
Fix coverity detected issues in option.c

Error: STRING_OVERFLOW (CWE-120): [#def99]
dnsmasq-2.86test7/src/option.c:801: fixed_size_dest: You might overrun the 100-character fixed-size string "buff" by copying "usage[i].arg" without checking the length.
#  799|         if (usage[i].arg)
#  800|    {
#  801|->    strcpy(buff, usage[i].arg);
#  802|      for (j = 0; tab[j].handle; j++)
#  803|        if (tab[j].handle == *(usage[i].arg))

Error: CLANG_WARNING: [#def100]
dnsmasq-2.86test7/src/option.c:962:3: warning[deadcode.DeadStores]: Value stored to 'domain' is never read
#  960|       }
#  961|
#  962|->   domain += sprintf(domain, "in-addr.arpa");
#  963|
#  964|     return 1;

Error: CLANG_WARNING: [#def101]
dnsmasq-2.86test7/src/option.c:981:3: warning[deadcode.DeadStores]: Value stored to 'domain' is never read
#  979|         domain += sprintf(domain, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4);
#  980|       }
#  981|->   domain += sprintf(domain, "ip6.arpa");
#  982|
#  983|     return 1;

Error: RESOURCE_LEAK (CWE-772): [#def102] [important]
dnsmasq-2.86test7/src/option.c:1809: alloc_fn: Storage is returned from allocation function "opt_malloc".
dnsmasq-2.86test7/src/option.c:1809: var_assign: Assigning: "path" = storage returned from "opt_malloc(strlen(directory) + len + 2UL)".
dnsmasq-2.86test7/src/option.c:1810: noescape: Resource "path" is not freed or pointed-to in "strcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1811: noescape: Resource "path" is not freed or pointed-to in "strcat". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1812: noescape: Resource "path" is not freed or pointed-to in "strcat". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1815: noescape: Resource "path" is not freed or pointed-to in "stat".
dnsmasq-2.86test7/src/option.c:1809: overwrite_var: Overwriting "path" in "path = opt_malloc(strlen(directory) + len + 2UL)" leaks the storage that "path" points to.
# 1807|          continue;
# 1808|
# 1809|->      path = opt_malloc(strlen(directory) + len + 2);
# 1810|        strcpy(path, directory);
# 1811|        strcat(path, "/");

Error: RESOURCE_LEAK (CWE-772): [#def103] [important]
dnsmasq-2.86test7/src/option.c:1809: alloc_fn: Storage is returned from allocation function "opt_malloc".
dnsmasq-2.86test7/src/option.c:1809: var_assign: Assigning: "path" = storage returned from "opt_malloc(strlen(directory) + len + 2UL)".
dnsmasq-2.86test7/src/option.c:1810: noescape: Resource "path" is not freed or pointed-to in "strcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1811: noescape: Resource "path" is not freed or pointed-to in "strcat". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1812: noescape: Resource "path" is not freed or pointed-to in "strcat". [Note: The source code implementation of the function has been overridden by a builtin model.]
dnsmasq-2.86test7/src/option.c:1815: noescape: Resource "path" is not freed or pointed-to in "stat".
dnsmasq-2.86test7/src/option.c:1858: leaked_storage: Variable "path" going out of scope leaks the storage it points to.
# 1856|        free(files);
# 1857|      }
# 1858|->  break;
# 1859|         }
# 1860|

Error: RESOURCE_LEAK (CWE-772): [#def104] [important]
dnsmasq-2.86test7/src/option.c:1996: alloc_fn: Storage is returned from allocation function "canonicalise_opt".
dnsmasq-2.86test7/src/option.c:1996: var_assign: Assigning: "name" = storage returned from "canonicalise_opt(arg)".
dnsmasq-2.86test7/src/option.c:1998: leaked_storage: Variable "name" going out of scope leaks the storage it points to.
# 1996|    if (!(name = canonicalise_opt(arg)) ||
# 1997|        (comma && !(target = canonicalise_opt(comma))))
# 1998|->    ret_err(_("bad MX name"));
# 1999|
# 2000|    new = opt_malloc(sizeof(struct mx_srv_record));

Error: RESOURCE_LEAK (CWE-772): [#def106] [important]
dnsmasq-2.86test7/src/option.c:3477: alloc_fn: Storage is returned from allocation function "opt_malloc".
dnsmasq-2.86test7/src/option.c:3477: var_assign: Assigning: "new" = storage returned from "opt_malloc(96UL)".
dnsmasq-2.86test7/src/option.c:3618: leaked_storage: Variable "new" going out of scope leaks the storage it points to.
# 3616|          sprintf(errstr, _("duplicate dhcp-host IP address %s"),
# 3617|          daemon->addrbuff);
# 3618|->        return 0;
# 3619|        }
# 3620|          }

Error: RESOURCE_LEAK (CWE-772): [#def108] [important]
dnsmasq-2.86test7/src/option.c:3781: alloc_fn: Storage is returned from allocation function "opt_malloc".
dnsmasq-2.86test7/src/option.c:3781: var_assign: Assigning: "new" = storage returned from "opt_malloc(32UL)".
dnsmasq-2.86test7/src/option.c:3786: leaked_storage: Variable "new" going out of scope leaks the storage it points to.
# 3784|
# 3785|    if (!(comma = split(arg)) || (len = strlen(comma)) == 0)
# 3786|->    ret_err(gen_err);
# 3787|
# 3788|    new->wildcard = 0;

Error: RESOURCE_LEAK (CWE-772): [#def109] [important]
dnsmasq-2.86test7/src/option.c:3921: alloc_fn: Storage is returned from allocation function "opt_malloc".
dnsmasq-2.86test7/src/option.c:3921: var_assign: Assigning: "new" = storage returned from "opt_malloc(56UL)".
dnsmasq-2.86test7/src/option.c:3994: leaked_storage: Variable "new" going out of scope leaks the storage it points to.
# 3992|       }
# 3993|
# 3994|->   ret_err(gen_err);
# 3995|          }
# 3996|

Error: CLANG_WARNING: [#def111]
dnsmasq-2.86test7/src/option.c:4693:25: warning[deadcode.DeadStores]: Value stored to 'tmp' during its initialization is never read
# 4691|    if (!canon)
# 4692|                     {
# 4693|->      struct name_list *tmp = new->names, *next;
# 4694|        for (tmp = new->names; tmp; tmp = next)
# 4695|

4 years agoAddress coverity issues detected in util.c
Petr Menšík [Sat, 11 Sep 2021 20:49:28 +0000 (21:49 +0100)]
Address coverity issues detected in util.c

4 years agoFix coverity warnings on dbus
Petr Menšík [Fri, 3 Sep 2021 15:19:05 +0000 (17:19 +0200)]
Fix coverity warnings on dbus

Error: CLANG_WARNING: [#def30]
dnsmasq-2.86test7/src/dbus.c:117:3: warning[deadcode.DeadStores]: Value stored to 'w' is never read
 #  115|     daemon->watches = w;
 #  116|
 #  117|->   w = data; /* no warning */
 #  118|     return TRUE;
 #  119|   }

Error: CLANG_WARNING: [#def31]
dnsmasq-2.86test7/src/dbus.c:137:3: warning[deadcode.DeadStores]: Value stored to 'w' is never read
 #  135|       }
 #  136|
 #  137|->   w = data; /* no warning */
 #  138|   }
 #  139|

Error: CHECKED_RETURN (CWE-252): [#def32]
dnsmasq-2.86test7/src/dbus.c:146: check_return: Calling "dbus_message_iter_init" without checking return value (as is done elsewhere 4 out of 5 times).
dnsmasq-2.86test7/src/dbus.c:460: example_checked: Example 1: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
dnsmasq-2.86test7/src/dbus.c:573: example_checked: Example 2: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
dnsmasq-2.86test7/src/dbus.c:257: example_checked: Example 3: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
dnsmasq-2.86test7/src/dbus.c:427: example_checked: Example 4: "dbus_message_iter_init(message, &iter)" has its value checked in "dbus_message_iter_init(message, &iter)".
 #  144|     char *domain;
 #  145|
 #  146|->   dbus_message_iter_init(message, &iter);
 #  147|
 #  148|     mark_servers(SERV_FROM_DBUS);

Error: NEGATIVE_RETURNS (CWE-394): [#def33]
dnsmasq-2.86test7/src/dbus.c:547: negative_return_fn: Function "parse_hex((char *)hwaddr, dhcp_chaddr, 16, NULL, &hw_type)" returns a negative number.
dnsmasq-2.86test7/src/dbus.c:547: assign: Assigning: "hw_len" = "parse_hex((char *)hwaddr, dhcp_chaddr, 16, NULL, &hw_type)".
dnsmasq-2.86test7/src/dbus.c:551: negative_returns: "hw_len" is passed to a parameter that cannot be negative.
 #  549|       hw_type = ARPHRD_ETHER;
 #  550|
 #  551|->   lease_set_hwaddr(lease, dhcp_chaddr, clid, hw_len, hw_type,
 #  552|                      clid_len, now, 0);
 #  553|     lease_set_expires(lease, expires, now);

Error: CLANG_WARNING: [#def34]
dnsmasq-2.86test7/src/dbus.c:722:3: warning[deadcode.DeadStores]: Value stored to 'method' is never read
 #  720|       clear_cache_and_reload(dnsmasq_time());
 #  721|
 #  722|->   method = user_data; /* no warning */
 #  723|
 #  724|     /* If no reply or no error, return nothing */

4 years agoRetry dhcp6 ping on interrupts
Petr Menšík [Fri, 3 Sep 2021 14:48:50 +0000 (16:48 +0200)]
Retry dhcp6 ping on interrupts

Error: CHECKED_RETURN (CWE-252): [#def35]
dnsmasq-2.86test7/src/dhcp6.c:295: check_return: Calling "sendto(dnsmasq_daemon->icmp6fd, &neigh, 24UL, 0, __CONST_SOCKADDR_ARG({.__sockaddr__ = &addr.sa}), 28U)" without checking return value. This library function may fail and return an error code.
 #  293|    break;
 #  294|
 #  295|->       sendto(daemon->icmp6fd, &neigh, sizeof(neigh), 0, &addr.sa, sizeof(addr));
 #  296|
 #  297|         ts.tv_sec = 0;

4 years agoFix coverity formats issues in blockdata
Petr Menšík [Fri, 3 Sep 2021 14:41:00 +0000 (16:41 +0200)]
Fix coverity formats issues in blockdata

Error: PRINTF_ARGS (CWE-686): [#def16]
dnsmasq-2.86test7/src/blockdata.c:56: invalid_type: Argument "blockdata_count * 48UL" to format specifier "%u" was expected to have type "unsigned int" but has type "unsigned long".
 #   54|   {
 #   55|     my_syslog(LOG_INFO, _("pool memory in use %u, max %u, allocated %u"),
 #   56|->      blockdata_count * sizeof(struct blockdata),
 #   57|        blockdata_hwm * sizeof(struct blockdata),
 #   58|        blockdata_alloced * sizeof(struct blockdata));

Error: PRINTF_ARGS (CWE-686): [#def17]
dnsmasq-2.86test7/src/blockdata.c:57: invalid_type: Argument "blockdata_hwm * 48UL" to format specifier "%u" was expected to have type "unsigned int" but has type "unsigned long".
 #   55|     my_syslog(LOG_INFO, _("pool memory in use %u, max %u, allocated %u"),
 #   56|        blockdata_count * sizeof(struct blockdata),
 #   57|->      blockdata_hwm * sizeof(struct blockdata),
 #   58|        blockdata_alloced * sizeof(struct blockdata));
 #   59|   }

Error: PRINTF_ARGS (CWE-686): [#def18]
dnsmasq-2.86test7/src/blockdata.c:58: invalid_type: Argument "blockdata_alloced * 48UL" to format specifier "%u" was expected to have type "unsigned int" but has type "unsigned long".
 #   56|        blockdata_count * sizeof(struct blockdata),
 #   57|        blockdata_hwm * sizeof(struct blockdata),
 #   58|->      blockdata_alloced * sizeof(struct blockdata));
 #   59|   }
 #   60|

4 years agoFix few coverity warnings in lease-tools
Petr Menšík [Fri, 3 Sep 2021 14:32:05 +0000 (16:32 +0200)]
Fix few coverity warnings in lease-tools

Error: UNINIT (CWE-457): [#def2]
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release.c:265: var_decl: Declaring variable "ifr" without initializer.
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release.c:285: uninit_use_in_call: Using uninitialized value "ifr". Field "ifr.ifr_ifru" is uninitialized when calling "setsockopt".
 #  283|     strncpy(ifr.ifr_name, argv[1], sizeof(ifr.ifr_name)-1);
 #  284|     ifr.ifr_name[sizeof(ifr.ifr_name)-1] = '\0';
 #  285|->   if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1)
 #  286|       {
 #  287|         perror("cannot setup interface");

Error: CHECKED_RETURN (CWE-252): [#def3]
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:346: check_return: Calling "inet_pton" without checking return value (as is done elsewhere 61 out of 72 times).
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:188: example_assign: Example 1: Assigning: "s" = return value from "inet_pton(10, ip, &result.ip)".
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:189: example_checked: Example 1 (cont.): "s" has its value checked in "s <= 0".
dnsmasq-2.86test7/src/cache.c:1108: example_checked: Example 2: "inet_pton(10, token, &addr)" has its value checked in "inet_pton(10, token, &addr) > 0".
dnsmasq-2.86test7/src/dbus.c:525: example_checked: Example 3: "inet_pton(2, ipaddr, &addr.addr4)" has its value checked in "inet_pton(2, ipaddr, &addr.addr4)".
dnsmasq-2.86test7/src/domain.c:138: example_checked: Example 4: "inet_pton(prot, tail, addr)" has its value checked in "inet_pton(prot, tail, addr)".
dnsmasq-2.86test7/src/lease.c:81: example_checked: Example 5: "inet_pton(10, dnsmasq_daemon->namebuff, &addr.addr6)" has its value checked in "inet_pton(10, dnsmasq_daemon->namebuff, &addr.addr6)".
 #  344|       client_addr.sin6_flowinfo = 0;
 #  345|       client_addr.sin6_scope_id =0;
 #  346|->     inet_pton(AF_INET6, "::", &client_addr.sin6_addr);
 #  347|       bind(sock, (struct sockaddr*)&client_addr, sizeof(struct sockaddr_in6));
 #  348|       inet_pton(AF_INET6, DHCP6_MULTICAST_ADDRESS, &server_addr.sin6_addr);

Error: CHECKED_RETURN (CWE-252): [#def4]
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:347: check_return: Calling "bind(sock, (struct sockaddr *)&client_addr, 28U)" without checking return value. This library function may fail and return an error code.
 #  345|       client_addr.sin6_scope_id =0;
 #  346|       inet_pton(AF_INET6, "::", &client_addr.sin6_addr);
 #  347|->     bind(sock, (struct sockaddr*)&client_addr, sizeof(struct sockaddr_in6));
 #  348|       inet_pton(AF_INET6, DHCP6_MULTICAST_ADDRESS, &server_addr.sin6_addr);
 #  349|       server_addr.sin6_port = htons(DHCP6_SERVER_PORT);

Error: CHECKED_RETURN (CWE-252): [#def5]
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:348: check_return: Calling "inet_pton" without checking return value (as is done elsewhere 61 out of 72 times).
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:188: example_assign: Example 1: Assigning: "s" = return value from "inet_pton(10, ip, &result.ip)".
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:189: example_checked: Example 1 (cont.): "s" has its value checked in "s <= 0".
dnsmasq-2.86test7/src/cache.c:1108: example_checked: Example 2: "inet_pton(10, token, &addr)" has its value checked in "inet_pton(10, token, &addr) > 0".
dnsmasq-2.86test7/src/dbus.c:525: example_checked: Example 3: "inet_pton(2, ipaddr, &addr.addr4)" has its value checked in "inet_pton(2, ipaddr, &addr.addr4)".
dnsmasq-2.86test7/src/domain.c:138: example_checked: Example 4: "inet_pton(prot, tail, addr)" has its value checked in "inet_pton(prot, tail, addr)".
dnsmasq-2.86test7/src/lease.c:81: example_checked: Example 5: "inet_pton(10, dnsmasq_daemon->namebuff, &addr.addr6)" has its value checked in "inet_pton(10, dnsmasq_daemon->namebuff, &addr.addr6)".
 #  346|       inet_pton(AF_INET6, "::", &client_addr.sin6_addr);
 #  347|       bind(sock, (struct sockaddr*)&client_addr, sizeof(struct sockaddr_in6));
 #  348|->     inet_pton(AF_INET6, DHCP6_MULTICAST_ADDRESS, &server_addr.sin6_addr);
 #  349|       server_addr.sin6_port = htons(DHCP6_SERVER_PORT);
 #  350|       int16_t recv_size = 0;

Error: NEGATIVE_RETURNS (CWE-394): [#def6]
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:360: var_tested_neg: Variable "recv_size" tests negative.
dnsmasq-2.86test7/contrib/lease-tools/dhcp_release6.c:373: negative_returns: "recv_size" is passed to a parameter that cannot be negative.
 #  371|      }
 #  372|
 #  373|->         int16_t result = parse_packet(response, recv_size);
 #  374|           if (result == NOT_REPLY_CODE)
 #  375|      {

4 years agoFix bunch of warnings in auth.c
Petr Menšík [Sat, 11 Sep 2021 16:56:01 +0000 (17:56 +0100)]
Fix bunch of warnings in auth.c

Error: CLANG_WARNING: [#def7]
dnsmasq-2.86test7/src/auth.c:420:5: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  418|          if (!found && is_name_synthetic(flag, name, &addr) )
 #  419|     {
 #  420|->     found = 1;
 #  421|       nxdomain = 0;
 #  422|

Error: CLANG_WARNING: [#def8]
dnsmasq-2.86test7/src/auth.c:436:8: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  434|        {
 #  435|          auth = soa = 1; /* inhibits auth section */
 #  436|->        found = 1;
 #  437|          log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<SOA>");
 #  438|        }

Error: CLANG_WARNING: [#def9]
dnsmasq-2.86test7/src/auth.c:472:8: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  470|          ns = 1; /* ensure we include NS records! */
 #  471|          axfr = 1;
 #  472|->        found = 1;
 #  473|          axfroffset = nameoffset;
 #  474|          log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<AXFR>");

Error: CLANG_WARNING: [#def10]
dnsmasq-2.86test7/src/auth.c:480:8: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  478|          auth = 1;
 #  479|          ns = 1; /* inhibits auth section */
 #  480|->        found = 1;
 #  481|          log_query(F_RRNAME | F_AUTH, zone->domain, NULL, "<NS>");
 #  482|        }

Error: CLANG_WARNING: [#def11]
dnsmasq-2.86test7/src/auth.c:501:4: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  499|    log_query(crecp->flags, name, &crecp->addr, record_source(crecp->uid));
 #  500|    *cut  = 0; /* remove domain part */
 #  501|->  found = 1;
 #  502|    if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
 #  503|    daemon->auth_ttl, NULL, qtype, C_IN,

Error: CLANG_WARNING: [#def12]
dnsmasq-2.86test7/src/auth.c:522:8: warning[deadcode.DeadStores]: Value stored to 'found' is never read
 #  520|       {
 #  521|         log_query(crecp->flags, name, &crecp->addr, record_source(crecp->uid));
 #  522|->       found = 1;
 #  523|         if (add_resource_record(header, limit, &trunc, nameoffset, &ansp,
 #  524|         daemon->auth_ttl, NULL, qtype, C_IN,

Error: CLANG_WARNING: [#def13]
dnsmasq-2.86test7/src/auth.c:617:8: warning[deadcode.DeadStores]: Value stored to 'p' is never read
 #  615|    p += sprintf(p, "%u.", a & 0xff);
 #  616|          a = a >> 8;
 #  617|->        p += sprintf(p, "%u.in-addr.arpa", a & 0xff);
 #  618|
 #  619|        }

Error: CPPCHECK_WARNING (CWE-758): [#def14]
dnsmasq-2.86test7/src/auth.c:627: warning[objectIndex]: The address of local variable 'addr6' might be accessed at non-zero index.
 #  625|          for (i = subnet->prefixlen-1; i >= 0; i -= 4)
 #  626|    {
 #  627|->    int dig = ((unsigned char *)&subnet->addr.addr6)[i>>3];
 #  628|      p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4);
 #  629|    }

Error: CLANG_WARNING: [#def15]
dnsmasq-2.86test7/src/auth.c:630:8: warning[deadcode.DeadStores]: Value stored to 'p' is never read
 #  628|      p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4);
 #  629|    }
 #  630|->        p += sprintf(p, "ip6.arpa");
 #  631|
 #  632|        }

4 years agoAdd safety checks to places pointed by Coverity
Petr Menšík [Wed, 18 Aug 2021 12:59:23 +0000 (14:59 +0200)]
Add safety checks to places pointed by Coverity

GCC Analyzer (experimental)

1. dnsmasq-2.85/src/forward.c:0: scope_hint: In function 'allocate_rfd.part.0'
2. dnsmasq-2.85/src/forward.c:2321:18: warning[-Wanalyzer-null-dereference]: dereference of NULL 'rfd'
 #  2319|     *fdlp = rfl;
 #  2320|
 #  2321|->   return rfl->rfd->fd;
 #  2322|   }
 #  2323|

1. dnsmasq-2.85/src/cache.c:0: scope_hint: In function 'log_query'
2. dnsmasq-2.85/src/cache.c:1969:20: warning[-Wanalyzer-null-dereference]: dereference of NULL 'name'
 #  1967|       source = "cached";
 #  1968|
 #  1969|->   if (strlen(name) == 0)
 #  1970|       name = ".";
 #  1971|

1. dnsmasq-2.85/src/cache.c:0: scope_hint: In function 'cache_scan_free'
2. dnsmasq-2.85/src/cache.c:436:20: warning[-Wanalyzer-null-argument]: use of NULL 'addr' where non-null expected
40. /usr/include/sys/un.h:37: included_from: Included from here.
41. dnsmasq-2.85/src/dnsmasq.h:101: included_from: Included from here.
42. dnsmasq-2.85/src/cache.c:17: included_from: Included from here.
43. /usr/include/string.h:64:12: note: argument 2 of 'memcmp' must be non-null
 #   434|       (flags & crecp->flags & F_REVERSE) &&
 #   435|       (flags & crecp->flags & (F_IPV4 | F_IPV6)) &&
 #   436|->     memcmp(&crecp->addr, addr, addrlen) == 0)
 #   437|        {
 #   438|          *up = crecp->hash_next;

4 years agoRetry on interrupted error in tftp
Petr Menšík [Wed, 18 Aug 2021 08:09:35 +0000 (10:09 +0200)]
Retry on interrupted error in tftp

Interrupt might arrive when sending error reply. Retry if possible.

Wrong Check of Return Value

10. dnsmasq-2.85/src/tftp.c:603: check_return: Calling "sendto(transfer->sockfd, dnsmasq_daemon->packet, len, 0, __CONST_SOCKADDR_ARG({.__sockaddr__ = &peer.sa}), sa_len(&peer))" without checking return value. This library function may fail and return an error code.
 #   601|      prettyprint_addr(&peer, daemon->addrbuff);
 #   602|      len = tftp_err(ERR_TID, daemon->packet, _("ignoring packet from %s (TID mismatch)"), daemon->addrbuff);
 #   603|->    sendto(transfer->sockfd, daemon->packet, len, 0, &peer.sa, sa_len(&peer));
 #   604|    }
 #   605|        }

4 years agoSmall sanity check in wildcard tag matching code.
Petr Menšík [Sat, 11 Sep 2021 13:26:03 +0000 (14:26 +0100)]
Small sanity check in wildcard tag matching code.

4 years agoAdd all current RR types to the table of type names used for query logging. v2.87test1
Dominik DL6ER [Fri, 10 Sep 2021 22:13:53 +0000 (23:13 +0100)]
Add all current RR types to the table of type names used for query logging.

This patch also changes the method of calling querystr() such that
it is only called when logging is enabled, to eliminate any
possible performance problems from searching the larger table.

4 years agocheck_name() determines if IDN processing is needed.
Gustaf Ullberg [Thu, 9 Sep 2021 23:13:39 +0000 (00:13 +0100)]
check_name() determines if IDN processing is needed.

Optimization that only runs IDN processing if it would alter the domain
name (non-ascii or uppercase characters).

This patch has conributions from Petr Menšík.

4 years agoRevert "Skip ascii-only names IDN processing"
Simon Kelley [Thu, 9 Sep 2021 23:02:11 +0000 (00:02 +0100)]
Revert "Skip ascii-only names IDN processing"

This reverts commit 9cb7f8a655596013dfdea2136ee6539be9905bd5.

4 years agoBump version in Debian changelog.
Simon Kelley [Wed, 8 Sep 2021 22:19:08 +0000 (23:19 +0100)]
Bump version in Debian changelog.

4 years agoSkip ascii-only names IDN processing
Petr Menšík [Wed, 8 Sep 2021 22:08:21 +0000 (23:08 +0100)]
Skip ascii-only names IDN processing

Calls to libidn on names without with only a-z A-Z - _ 0-9
have no effect, but are slow. This change elides those calls.

Patch inspire by analysis and an earlier patch from
Gustaf Ullberg <gustaf.ullberg@gmail.com>

4 years agoMerge branch 'nxdomain'
Simon Kelley [Wed, 8 Sep 2021 22:05:35 +0000 (23:05 +0100)]
Merge branch 'nxdomain'

4 years agoTreat ANY queries the same as CNAME queries WRT to DNSSEC on CNAME targets. v2.86
Simon Kelley [Wed, 8 Sep 2021 20:19:15 +0000 (21:19 +0100)]
Treat ANY queries the same as CNAME queries WRT to DNSSEC on CNAME targets.

4 years agoTreat ANY queries the same as CNAME queries WRT to DNSSEC on CNAME targets. holly/nxdomain
Simon Kelley [Wed, 8 Sep 2021 20:19:15 +0000 (21:19 +0100)]
Treat ANY queries the same as CNAME queries WRT to DNSSEC on CNAME targets.

4 years agoCaching cleanup. Use cached NXDOMAIN to answer queries of any type.
Simon Kelley [Sun, 5 Sep 2021 17:47:45 +0000 (18:47 +0100)]
Caching cleanup. Use cached NXDOMAIN to answer queries of any type.

4 years agoAdd RFC 4833 DHCP options "posix-timezone" and "tzdb-timezone".
DL6ER [Fri, 3 Sep 2021 11:51:18 +0000 (13:51 +0200)]
Add RFC 4833 DHCP options "posix-timezone" and "tzdb-timezone".

Signed-off-by: DL6ER <dl6er@dl6er.de>
4 years agoGet logging of DNSSEC status right when Checking Disabled bit set.
Simon Kelley [Thu, 2 Sep 2021 09:07:08 +0000 (10:07 +0100)]
Get logging of DNSSEC status right when Checking Disabled bit set.

4 years agoFinal logging tweaks. v2.86rc3
Dominik DL6ER [Wed, 1 Sep 2021 20:19:47 +0000 (21:19 +0100)]
Final logging tweaks.

4 years agoRationalise query-reply logging. v2.86rc2
Simon Kelley [Tue, 31 Aug 2021 17:23:03 +0000 (18:23 +0100)]
Rationalise query-reply logging.

Try and log exactly what was returned, rather than just what
got cached. Also give validation status of RRsets if extra logging specified.

This commit also fixes a long-standing bug in caching of CNAME chains
leading to a PTR record.

Based on and inspired by a patch from Dominik DL6ER <dl6er@dl6er.de>

4 years agoSupport limited wildcards in the input tags for --tag-if.
Geoff Back [Sun, 29 Aug 2021 12:27:27 +0000 (13:27 +0100)]
Support limited wildcards in the input tags for --tag-if.

4 years agoMan page BNF error fix. v2.86rc1
Geert Stappers via Dnsmasq-discuss [Mon, 16 Aug 2021 21:59:28 +0000 (23:59 +0200)]
Man page BNF error fix.

Move dhcp-range bracket indicating option.

There should already be an end-address or mode  when adding a netmask.

Also the date bumped.

Signed-off-by: Geert Stappers <stappers@stappers.nl>
4 years agoMerge message changes into I18N files.
Simon Kelley [Wed, 25 Aug 2021 13:11:42 +0000 (14:11 +0100)]
Merge message changes into I18N files.

4 years agoFix empty domain in server option parsing when more than one domain is given
Dominik DL6ER [Fri, 20 Aug 2021 11:05:35 +0000 (13:05 +0200)]
Fix empty domain in server option parsing when more than one domain is given

Signed-off-by: DL6ER <dl6er@dl6er.de>
4 years agoMake comment style consistent.
Etan Kissling [Thu, 22 Jul 2021 12:19:11 +0000 (12:19 +0000)]
Make comment style consistent.

Majority of code base does not use C90-style // end of line comments.
This formats the few existing exceptions using /* */ for consistency.

4 years agoAdjust logging levels for connmark patterns.
Etan Kissling [Thu, 22 Jul 2021 12:08:18 +0000 (12:08 +0000)]
Adjust logging levels for connmark patterns.

This brings the log levels emitted by connmark pattern code in line with
the rest of the code base. LOG_DEBUG is used for diagnostics that may be
verbose depending on the request patterns. LOG_ERR is used for problems
with the implementation itself.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoRe-order UBus teardown logic.
Etan Kissling [Thu, 22 Jul 2021 11:41:28 +0000 (11:41 +0000)]
Re-order UBus teardown logic.

When destroying the UBus context, private fields of our ubus_object were
being reset to 0 while UBus was still owning those objects. While this
seems to work out fine, it seems cleaner to first release the object so
that UBus no longer owns it, before proceding to reset those fields.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoEliminate redundant UBus `notify` variable.
Etan Kissling [Thu, 22 Jul 2021 11:40:54 +0000 (11:40 +0000)]
Eliminate redundant UBus `notify` variable.

There was a `notify` variable to keep track whether a subscriber is
observing our UBus object. However, it was not properly cleaned up in
`ubus_destroy`, potentially becoming stale over UBus reconnections.
The variable was removed and the current state is examined when sending
notifications, similarly as is done in other existing OpenWrt code.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoHandle UBus serialization errors.
Etan Kissling [Thu, 22 Jul 2021 12:07:30 +0000 (12:07 +0000)]
Handle UBus serialization errors.

The various blob / blobmsg commands can fail, e.g., when memory is low.
Previously, those errors were silently discarded. This patch adds checks
for the error conditions, logging them and exiting from the functions.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoRevert "There was a `notify` variable to keep track whether a subscriber is"
Simon Kelley [Thu, 12 Aug 2021 16:00:10 +0000 (17:00 +0100)]
Revert "There was a `notify` variable to keep track whether a subscriber is"

This reverts commit ea43234c868e4136d900f35a19aaedcfd9f96c70.

4 years agoRevert "Re-order UBus teardown logic."
Simon Kelley [Thu, 12 Aug 2021 15:58:30 +0000 (16:58 +0100)]
Revert "Re-order UBus teardown logic."

This reverts commit d387f8f06c68b43d549388413d996bef63e4b9f6.

4 years agoDefine order of reading files when --addn-hosts given a directory.
Simon Kelley [Thu, 12 Aug 2021 15:48:54 +0000 (16:48 +0100)]
Define order of reading files when --addn-hosts given a directory.

Also applies to --dhcp-hostsfile and --dhcp-optsfile though it is
less useful there.

4 years agoFiz sizeof() confusion in 527c3c7d0d3bb4bf5fad699f10cf0d1a45a54692 v2.86test7
Simon Kelley [Wed, 11 Aug 2021 08:10:39 +0000 (09:10 +0100)]
Fiz sizeof() confusion in 527c3c7d0d3bb4bf5fad699f10cf0d1a45a54692

4 years agodhcp_buff2 not availble in log_packet, use daemon->addrbuff
Simon Kelley [Tue, 10 Aug 2021 22:54:13 +0000 (23:54 +0100)]
dhcp_buff2 not availble in log_packet, use daemon->addrbuff

4 years agoMerge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq
Simon Kelley [Tue, 10 Aug 2021 22:15:46 +0000 (23:15 +0100)]
Merge branch 'master' of ssh://thekelleys.org.uk/var/local/git/dnsmasq

4 years agoRemove remaining uses of deprecated inet_ntoa()
Petr Menšík [Tue, 10 Aug 2021 21:50:33 +0000 (22:50 +0100)]
Remove remaining uses of  deprecated inet_ntoa()

4 years agoRemove remaining uses of deprecated inet_addr() function.
Petr Menšík [Tue, 10 Aug 2021 21:21:01 +0000 (22:21 +0100)]
Remove remaining uses of deprecated inet_addr() function.

4 years agoCHANGELOG: spell-check
Matthias Andree [Tue, 10 Aug 2021 20:40:06 +0000 (21:40 +0100)]
CHANGELOG: spell-check

4 years agoRe-order UBus teardown logic.
Etan Kissling [Thu, 22 Jul 2021 11:41:28 +0000 (11:41 +0000)]
Re-order UBus teardown logic.

When destroying the UBus context, private fields of our ubus_object were
being reset to 0 while UBus was still owning those objects. While this
seems to work out fine, it seems cleaner to first release the object so
that UBus no longer owns it, before proceding to reset those fields.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoThere was a `notify` variable to keep track whether a subscriber is
Etan Kissling [Tue, 10 Aug 2021 20:15:09 +0000 (21:15 +0100)]
There was a `notify` variable to keep track whether a subscriber is
observing our UBus object. However, it was not properly cleaned up in
`ubus_destroy`, potentially becoming stale over UBus reconnections.
The variable was removed and the current state is examined when sending
notifications, similarly as is done in other existing OpenWrt code.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoFix NOERR/NXDOMAIN in answers configured by --domain-needed.
Simon Kelley [Sun, 8 Aug 2021 20:28:29 +0000 (21:28 +0100)]
Fix NOERR/NXDOMAIN in answers configured by --domain-needed.

4 years agoCONNTRACK needs CAP_NET_ADMIN.
Simon Kelley [Thu, 5 Aug 2021 22:40:04 +0000 (23:40 +0100)]
CONNTRACK needs CAP_NET_ADMIN.

4 years agoBetter fix than f2266d9678d71633d62d70238be3782ea74019c9 v2.86test6
Simon Kelley [Wed, 21 Jul 2021 20:27:14 +0000 (21:27 +0100)]
Better fix than f2266d9678d71633d62d70238be3782ea74019c9

4 years agoAdd UINT32_MAX if not defined by system.
Simon Kelley [Tue, 20 Jul 2021 23:23:28 +0000 (00:23 +0100)]
Add UINT32_MAX if not defined by system.

4 years agoTypo in new EDE code.
Simon Kelley [Tue, 20 Jul 2021 23:15:58 +0000 (00:15 +0100)]
Typo in new EDE code.

4 years agoHandle empty hostmaster in --auth-soa
Simon Kelley [Tue, 20 Jul 2021 23:15:15 +0000 (00:15 +0100)]
Handle empty hostmaster in --auth-soa

Spotted by Max Julian Hofmann and the Advanced Research Team at CrowdStrike

4 years agoDetect malformed --dhcp-relay option.
Simon Kelley [Tue, 20 Jul 2021 22:49:38 +0000 (23:49 +0100)]
Detect malformed --dhcp-relay option.

Spotted by Max Julian Hofmann and the Advanced Research Team at CrowdStrike

4 years agoFix argument checking for --dhcp-match.
Simon Kelley [Tue, 20 Jul 2021 22:45:36 +0000 (23:45 +0100)]
Fix argument checking for --dhcp-match.

Spotted by Max Julian Hofmann and the Advanced Research Team at CrowdStrike

4 years agocanonicalise_opt must always return heap memory.
Simon Kelley [Tue, 20 Jul 2021 22:22:37 +0000 (23:22 +0100)]
canonicalise_opt must always return heap memory.

Thanks to Max Julian Hofmann for spotting this.

4 years agoChecks on prefix-length in --domain --synth-domain and --rev-server.
Simon Kelley [Tue, 20 Jul 2021 22:13:58 +0000 (23:13 +0100)]
Checks on prefix-length in --domain --synth-domain and --rev-server.

4 years agoReturn REFUSED in auth mode when we are not authoritative for the query.
Simon Kelley [Tue, 20 Jul 2021 16:15:36 +0000 (17:15 +0100)]
Return REFUSED in auth mode when we are not authoritative for the query.

4 years ago--synth-domain now works in auth mode.
Simon Kelley [Sun, 18 Jul 2021 23:10:49 +0000 (00:10 +0100)]
--synth-domain now works in auth mode.

4 years agoAllow shorter IPv6 prefix lengths in (some) --synth-domain options.
Simon Kelley [Sun, 18 Jul 2021 17:18:56 +0000 (18:18 +0100)]
Allow shorter IPv6 prefix lengths in (some) --synth-domain options.

4 years agoAdd --quiet-tftp.
Kevin Darbyshire-Bryant [Fri, 9 Jul 2021 21:48:49 +0000 (22:48 +0100)]
Add --quiet-tftp.

4 years agoAdd EDE return when no matching key found. v2.86test5
Dominik DL6ER [Fri, 9 Jul 2021 21:12:42 +0000 (22:12 +0100)]
Add EDE return when no matching key found.

4 years agoSubtle change to priority of --server types.
Simon Kelley [Tue, 6 Jul 2021 20:02:35 +0000 (21:02 +0100)]
Subtle change to priority of --server types.

Make --server=/example.com/1.2.3.4 take priority over
--server=/example.com/ (AKA --address=/example.com/ or --local=/example.com/)

This corrects a regression in the domain-match rewrite, and appears
to be the more useful order. It got swapped because I didn't consider
that both could usefully co-exist.

4 years agoFix thinko in a92c6d77dcd475579c39bdff141f5eb128e2a048
Kevin Darbyshire-Bryant [Mon, 5 Jul 2021 20:00:47 +0000 (21:00 +0100)]
Fix thinko in a92c6d77dcd475579c39bdff141f5eb128e2a048

4 years agoFix logical error in d0ae3f5a4dc094e8fe2a3c607028c1c59f42f473
Simon Kelley [Mon, 5 Jul 2021 19:56:11 +0000 (20:56 +0100)]
Fix logical error in d0ae3f5a4dc094e8fe2a3c607028c1c59f42f473

The code which checked for a possible local answer to a domain,
like --address=/example.com/1.2.3.4 could return false positives,
causing upstream NXDOMAIN replies to be rewritten as NOERROR.

Thanks to Dominik DL6ER for the bug report and analysis.

4 years agoAdd calls to dump internally generated answers for dumpmask=0x0002
Simon Kelley [Sun, 4 Jul 2021 22:12:14 +0000 (23:12 +0100)]
Add calls to dump internally generated answers for dumpmask=0x0002

4 years agoFix order of calls to resize-packet() and add_pseudoheader().
Simon Kelley [Sun, 4 Jul 2021 21:38:26 +0000 (22:38 +0100)]
Fix order of calls to resize-packet() and add_pseudoheader().

Avoids malformed replies with EDE in certain circumstances.

4 years agoSupport IPv6 in --bogus-nxdomian and --ignore-address
Simon Kelley [Sun, 4 Jul 2021 21:27:00 +0000 (22:27 +0100)]
Support IPv6 in --bogus-nxdomian and --ignore-address

4 years agoMake --rebind-localhost-ok apply to :: and 0.0.0.0
Simon Kelley [Sun, 4 Jul 2021 20:09:10 +0000 (21:09 +0100)]
Make --rebind-localhost-ok apply to :: and 0.0.0.0

Also make the definition of local IPv6 addresses
the same for --bogus-priv and rebind protection.

4 years agoTidy domain parsing, make --server=/*/1.2.3.4 equivalent to --server=1.2.3.4
Simon Kelley [Sat, 3 Jul 2021 11:56:50 +0000 (12:56 +0100)]
Tidy domain parsing, make --server=/*/1.2.3.4 equivalent to --server=1.2.3.4

4 years agoModify and propagate changed lease.
Petr Menšík [Fri, 2 Jul 2021 15:58:48 +0000 (16:58 +0100)]
Modify and propagate changed lease.

If hostname is reset on existing lease, propagate such change to leases
file and script.

4 years agoRationalise SERV_MARK use.
Simon Kelley [Thu, 1 Jul 2021 22:00:22 +0000 (23:00 +0100)]
Rationalise SERV_MARK use.

4 years agoFix oversight in build_server_array().
Simon Kelley [Thu, 1 Jul 2021 21:35:18 +0000 (22:35 +0100)]
Fix oversight in  build_server_array().

The index computation went awry when servers are disabled
by the loop-detection system.

Thanks to Xingcong Li for spotting this.

4 years agoAllow wildcards in domain patterns.
Simon Kelley [Thu, 1 Jul 2021 21:28:24 +0000 (22:28 +0100)]
Allow wildcards in domain patterns.

Domain patterns in --address, --server and --local have, for many years,
matched complete labels only, so
--server=/google.com/1.2.3.4
will apply to google.com and www.google.com but NOT supergoogle.com

This commit introduces an optional '*' at the LHS of the domain string which
changes this behaviour so as to include substring matches _within_ labels. So,
--server=/*google.com/1.2.3.4
applies to google.com, www.google.com AND supergoogle.com.

4 years agoReuse workspace bit in struct server ->flags.
Simon Kelley [Thu, 1 Jul 2021 12:22:10 +0000 (13:22 +0100)]
Reuse workspace bit in struct server ->flags.

4 years agoFix ipset support.
Etan Kissling [Tue, 29 Jun 2021 13:48:25 +0000 (13:48 +0000)]
Fix ipset support.

This fixes a problem with ipset processing that got recently introduced
when `extract_request` filtering was tightened. During the recent change
an incorrect assumption was made that `extract_request` was only called
for requests but with ipset it is also called when processing responses.

The fix ensures that the new filters only apply to requests (QR=0 @ hdr)

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
4 years agoRevert "Treat failure of ubus_add_object() in ubus_init() as retry-able."
Simon Kelley [Wed, 30 Jun 2021 11:30:15 +0000 (12:30 +0100)]
Revert "Treat failure of ubus_add_object() in ubus_init() as retry-able."

This reverts commit 8a1ef367e27e570cac40d3b09920a4a60c5f7e0b.

4 years agoTreat failure of ubus_add_object() in ubus_init() as retry-able.
Simon Kelley [Sun, 27 Jun 2021 20:32:10 +0000 (21:32 +0100)]
Treat failure of ubus_add_object() in ubus_init() as retry-able.

3c93e8eb41952a9c91699386132d6fe83050e9be regularised ubus_init()
by avoiding logging calls (it can be called before logging is up)
but it instead returned any error from ubus_add_object() which
made such an error fatal. It turns out this is awkward, so this
patch returns NULL always, so that the event-loop will continue
attemping to connect to ubus forever.

This is not necessarily optimal either, and should be looked at
by a UBUS grown-up, but it does solve the immediate problem.

4 years agoFix trivial breakage of DBUS done by 85bc7534dae7711f6c82742feaa7dacb41af3f36
Simon Kelley [Sun, 27 Jun 2021 20:16:30 +0000 (21:16 +0100)]
Fix trivial breakage of DBUS done by 85bc7534dae7711f6c82742feaa7dacb41af3f36

4 years agoCompiler warnings.
Simon Kelley [Sun, 27 Jun 2021 20:03:52 +0000 (21:03 +0100)]
Compiler warnings.

4 years agoTidy up interface to dbus and ubus modules.
Simon Kelley [Sun, 27 Jun 2021 19:56:58 +0000 (20:56 +0100)]
Tidy up interface to dbus and ubus modules.

Consistently treat a non-NULL return from [ud]bus-init() as a fatal error:
either die() if still starting, or log an error and disable
the relevant module if dnsmasq has already started.

Also rationalise calls to set and check listeners depending on
configuration.

4 years agoFix problem with re-allocation of serverarray. v2.86test4
Simon Kelley [Sat, 26 Jun 2021 20:13:41 +0000 (21:13 +0100)]
Fix problem with re-allocation of serverarray.

4 years agoRationalise domain parsing for --rev-server and --domain.
Simon Kelley [Sat, 26 Jun 2021 17:51:05 +0000 (18:51 +0100)]
Rationalise domain parsing for --rev-server and --domain.