2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-28 13:08:06 +00:00

7702 Commits

Author SHA1 Message Date
Matthijs Mekking
a9a9aa7fd8 Add parentheses around return values 2020-02-06 10:17:22 +01:00
Matthijs Mekking
b378d0371f Fix kasp bug new KSK on restart [#1593]
When you do a restart or reconfig of named, or rndc loadkeys, this
triggers the key manager to run.  The key manager will check if new
keys need to be created. If there is an active key, and key rollover
is scheduled far enough away, no new key needs to be created.

However, there was a bug that when you just start to sign your zone,
it takes a while before the KSK becomes an active key. An active KSK
has its DS submitted or published, but before the key manager allows
that, the DNSKEY needs to be omnipresent. If you restart named
or rndc loadkeys in quick succession when you just started to sign
your zone, new keys will be created because the KSK is not yet
considered active.

Fix is to check for introducing as well as active keys. These keys
all have in common that their goal is to become omnipresent.
2020-02-06 10:17:22 +01:00
Mark Andrews
fccf65a585 'dctx' must be non NULL, remove test.
1549 cleanup:
1550        if (dctx->dbiter != NULL)
1551                dns_dbiterator_destroy(&dctx->dbiter);
1552        if (dctx->db != NULL)
1553                dns_db_detach(&dctx->db);

	CID 1452686 (#1 of 1): Dereference before null check (REVERSE_INULL)
	check_after_deref: Null-checking dctx suggests that it may
	be null, but it has already been dereferenced on all paths
	leading to the check.

1554        if (dctx != NULL)
1555                isc_mem_put(mctx, dctx, sizeof(*dctx));
2020-02-05 18:37:17 +11:00
Mark Andrews
0312e73e16 'closest' must be non NULL, remove test.
6412 cleanup:
6413        dns_rdataset_disassociate(&neg);
6414        dns_rdataset_disassociate(&negsig);

	CID 1452700 (#1 of 1): Dereference before null check (REVERSE_INULL)
	check_after_deref: Null-checking closest suggests that it
	may be null, but it has already been dereferenced on all
	paths leading to the check.

6415        if (closest != NULL)
6416                free_noqname(mctx, &closest);
2020-02-05 18:37:17 +11:00
Mark Andrews
2e189bb053 'stub' cannot be non NULL, remove test.
13429 cleanup:
13430        cancel_refresh(zone);

	CID 1452702 (#1 of 1): Dereference before null check (REVERSE_INULL)
	check_after_deref: Null-checking stub suggests that it may
	be null, but it has already been dereferenced on all paths
	leading to the check.

13431        if (stub != NULL) {
13432                stub->magic = 0;
2020-02-05 18:37:17 +11:00
Mark Andrews
1b1a94ea6d 'noqname' must be non NULL, remove test.
6367cleanup:
6368        dns_rdataset_disassociate(&neg);
6369        dns_rdataset_disassociate(&negsig);

	CID 1452704 (#1 of 1): Dereference before null check
	(REVERSE_INULL) check_after_deref: Null-checking noqname
	suggests that it may be null, but it has already been
	dereferenced on all paths leading to the check.

6370        if (noqname != NULL)
6371                free_noqname(mctx, &noqname);
2020-02-05 18:37:17 +11:00
Mark Andrews
e4d08c0232 'event' must be non NULL, remove test.
1401        }

	CID 1453455 (#1 of 1): Dereference before null check (REVERSE_INULL)
	check_after_deref: Null-checking event suggests that it may be null,
	but it has already been dereferenced on all paths leading to the check.

1402        if (event != NULL)
1403                isc_event_free(ISC_EVENT_PTR(&event));
2020-02-05 18:37:17 +11:00
Mark Andrews
1efc7550a3 keymgr_keyrole couldn't emit "NOSIGN".
92        } else {
 93                return ("ZSK");
 94        }

	CID 1455900 (#1 of 1): Structurally dead code (UNREACHABLE)
	unreachable: This code cannot be reached: return "NOSIGN";.

 95        return ("NOSIGN");
2020-02-05 18:37:17 +11:00
Mark Andrews
5fc9efba30 Remove dead error code.
128        return (ISC_R_SUCCESS);
129

	CID 1456146 (#1 of 1): Structurally dead code (UNREACHABLE)
	unreachable: This code cannot be reached: {
	   if (dst->labels[i] != N....

130        do {
2020-02-05 18:37:17 +11:00
Mark Andrews
aa101260d9 'indentctx' is always defined. Just use it.
402        ctx->serve_stale_ttl = 0;

	notnull: At condition indentctx, the value of indentctx
	cannot be NULL.  dead_error_condition: The condition indentctx
	must be true.

	CID 1456147 (#1 of 1): Logically dead code (DEADCODE)
	dead_error_line: Execution cannot reach the expression
	default_indent inside this statement: ctx->indent = (indentctx
	? ....

403        ctx->indent = indentctx ? *indentctx : default_indent;
2020-02-05 18:37:17 +11:00
Mark Andrews
331b74d6bf dstkey is no longer used 2020-02-05 18:37:17 +11:00
Mark Andrews
a038f77d92 'buffer' must be non-NULL as isc_buffer_allocate can no longer fail.
1636 cleanup:

CID 1458130 (#1 of 1): Dereference before null check (REVERSE_INULL)
check_after_deref: Null-checking buffer suggests that it may be
null, but it has already been dereferenced on all paths leading to
the check.

1637        if (buffer != NULL)
1638                isc_buffer_free(&buffer);
2020-02-05 18:37:17 +11:00
Ondřej Surý
a9bd6f6ea6 Fix comparison between type uint16_t and wider type size_t in a loop
Found by LGTM.com (see below for description), and while it should not
happen as EDNS OPT RDLEN is uint16_t, the fix is easy.  A little bit
of cleanup is included too.

> In a loop condition, comparison of a value of a narrow type with a value
> of a wide type may result in unexpected behavior if the wider value is
> sufficiently large (or small). This is because the narrower value may
> overflow. This can lead to an infinite loop.
2020-02-05 01:41:13 +00:00
Matthijs Mekking
37b41ff693 Simplify cachedb rrset statistic counters
This commit simplifies the cachedb rrset statistics in two ways:
- Introduce new rdtypecounter arithmetics, allowing bitwise
  operations.
- Remove the special DLV statistic counter.

New rdtypecounter arithmetics
-----------------------------
"The rdtypecounter arithmetics is a brain twister".  Replace the
enum counters with some defines.  A rdtypecounter is now 8 bits for
RRtypes and 3 bits for flags:

      0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    |  |  |  |  |  |  S  |NX|         RRType        |
    +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

If the 8 bits for RRtype are all zero, this is an Other RRtype.

Bit 7 is the NXRRSET (NX) flag and indicates whether this is a
positive (0) or a negative (1) RRset.

Then bit 5 and 6 mostly tell you if this counter is for an active,
stale, or ancient RRtype:

    S = 0x00 means Active
    S = 0x01 means Stale
    S = 0x10 means Ancient

Since a counter cannot be stale and ancient at the same time, we
treat S = 0x11 as a special case to deal with NXDOMAIN counters.

S = 0x11 indicates an NXDOMAIN counter and in this case the RRtype
field signals the expiry of this cached item:

    RRType = 0 means Active
    RRType = 1 means Stale
    RRType = 2 means Ancient
2020-02-04 11:58:34 +01:00
Matthijs Mekking
3079956ff7 Remove the DLV statistics counter
This also removes counting the DLV RRtype separately.  Since we have
deprecated the lookaside validation it makes no sense to keep this
special statistic counter.
2020-02-04 11:58:34 +01:00
Ondřej Surý
c00def343f Suppress cppcheck false positive nullPointerArithmeticRedundantCheck 2020-02-04 11:09:22 +01:00
Mark Andrews
bb65e57297 isc_mem_get cannot fail 2020-02-04 11:09:22 +01:00
Mark Andrews
d6de520bd1 delay assignment until after REQUIRE 2020-02-04 11:09:22 +01:00
Mark Andrews
704b9ee9d0 skip if first is NULL 2020-02-04 11:09:22 +01:00
Evan Hunt
dba0163dac Correctly handle catalog zone entries containing slashes
- Add quotes before and after zone name when generating "addzone"
  input so avoid "unexpected token" errors.
- Use a hex digest for zone filenames when the zone or view name
  contains a slash.
- Test with a domain name containing a slash.
- Incidentally added 'catzhash.py' to contrib/scripts to generate
  hash labels for catalog zones, as it was needed to write the test.
2020-02-03 16:08:20 -08:00
Ondřej Surý
c73e5866c4 Refactor the isc_buffer_allocate() usage using the semantic patch
The isc_buffer_allocate() function now cannot fail with ISC_R_MEMORY.
This commit removes all the checks on the return code using the semantic
patch from previous commit, as isc_buffer_allocate() now returns void.
2020-02-03 08:29:00 +01:00
Ondřej Surý
5eb3f71a3e Refactor the isc_mempool_create() usage using the semantic patch
The isc_mempool_create() function now cannot fail with ISC_R_MEMORY.
This commit removes all the checks on the return code using the semantic
patch from previous commit, as isc_mempool_create() now returns void.
2020-02-03 08:27:16 +01:00
Mark Andrews
02c2fc5ad3 use anonomous constants 2020-01-30 11:29:27 +11:00
Mark Andrews
7c0d9dac9f use enum 2020-01-30 11:29:27 +11:00
Mark Andrews
279f6b01de style 2020-01-30 11:18:16 +11:00
Mark Andrews
a09c464a20 return the correct error code for the type being checked 2020-01-30 11:18:16 +11:00
Mark Andrews
f91b3a69ce check that a CDNSKEY deletion record is accepted 2020-01-30 11:18:16 +11:00
Mark Andrews
0adb4b25d3 handle CDS deletion record in consistancy checks 2020-01-30 11:18:16 +11:00
Tony Finch
f3f7b7df5d Send NOFITY messages after deleting private-type records.
The `rndc signing -clear` command cleans up the private-type records
that keep track of zone signing activity, but before this change it
did not tell the secondary servers that the zone has changed.
2020-01-23 07:36:03 +00:00
Diego Fronza
85555f29d7 Fixed crash when querying for non existing domain in chaos class
Function dns_view_findzonecut in view.c wasn't correctly handling
classes other than IN (chaos, hesiod, etc) whenever the name being
looked up wasn't in cache or in any of the configured zone views' database.

That resulted in a NULL fname being used in resolver.c:4900, which
in turn was triggering abort.
2020-01-22 16:15:51 -03:00
Witold Kręcicki
741bc11bdb dnssec: use less-or-equal when looking at SyncPublish time
If we created a key, mark its SyncPublish time as 'now' and started
bind the key might not be published if the SyncPublish time is in
the same second as the time the zone is loaded. This is mostly
for dnssec system test, as this kind of scenario is very unlikely
in a real world environment.
2020-01-21 14:37:53 +01:00
Tony Finch
4227b7969b dnssec: do not publish CDS records when -Psync is in the future
This is a bug I encountered when trying to schedule an algorithm
rollover. My plan, for a zone whose maximum TTL is 48h, was to sign
with the new algorithm and schedule a change of CDS records for more
than 48 hours in the future, roughly like this:

    $ dnssec-keygen -a 13 -fk -Psync now+50h $zone
    $ dnssec-keygen -a 13 $zone
    $ dnssec-settime -Dsync now+50h $zone_ksk_old

However the algorithm 13 CDS was published immediately, which could
have made the zone bogus.

To reveal the bug using the `smartsign` test, this change just adds a
KSK with all its times in the future, so it should not affect the
existing checks at all. But the final check (that there are no CDS or
CDSNSKEY records after -Dsync) fails with the old `syncpublish()`
logic, because the future key's sync records appear early. With the
new `syncpublish()` logic the future key does not affect the test, as
expected, and it now passes.
2020-01-21 16:39:31 +11:00
Tony Finch
3b1bd3f48b Omit spurious newlines when reporting DNSKEY changes
These caused blank lines to appear in the logs.
2020-01-21 15:55:24 +11:00
Tinderbox User
05f2241fcb prep 9.15.8 2020-01-16 08:01:20 +00:00
Evan Hunt
6a1c41143f fix a bug when validating negative cache entries
if validator_start() is called with validator->event->message set to
NULL, we can't use message->rcode to decide which negative proofs are
needed, so we use the rdataset attributes instead to determine whether
the rdataset was cached as NXDOMAIN or NODATA.
2020-01-15 13:55:33 -08:00
Evan Hunt
6799a222d1 keep the keynode attached as long as dsset is in use
when using the trust anchor dsset as val->dsset, keep a reference
to the keynode so dsset can't be freed.
2020-01-14 09:26:19 -08:00
Evan Hunt
2d249ebeae make dns_keytable_deletekey() work correctly
it now removes matching trust anchors from from the dslist while leaving
the other trust anchors in place.

also cleaned up the API to remove functions that were never being used.
2020-01-14 09:26:13 -08:00
Evan Hunt
678e2d3cfa fix a bug with the insertion of DS records into existing keynodes
NOTE: the keytable test is still failing because dns_keytable_deletekey()
is looking for exact matches in keynodes containing dst_key objects,
which no keynode has anymore.
2020-01-14 09:24:23 -08:00
Evan Hunt
b984a4b647 disable adding keys to keytable; only DS trust anchors can now be added
the internal keytable structure has not yet been changed, but
insertion of DS anchors is the only method now available.

NOTE: the keytable unit test is currently failing because of tests
that expect individual keynode objects to contain single DST key
objects.
2020-01-14 09:24:22 -08:00
Evan Hunt
7fdf40770f remove all code that uses non-DS trust anchors
as initial-key and static-key trust anchors will now be stored as a
DS rrset, code referencing keynodes storing DNSKEY trust anchors will
no longer be reached.
2020-01-14 09:24:13 -08:00
Evan Hunt
21d3f66f1c rename dns_keytable_deletekeynode to dns_keytable_deletekey
this function is used by dns_view_untrust() to handle revoked keys, so
it will still be needed after the keytable/validator refactoring is
complete, even though the keytable will be storing DS trust anchors
instead of keys. to simplify the way it's called, it now takes a DNSKEY
rdata struct instead of a DST key.
2020-01-14 09:23:21 -08:00
Ondřej Surý
ede2208d96 ATOMIC_VAR_INIT() must be used only for static variables (C17) 2020-01-14 13:12:13 +01:00
Ondřej Surý
64e2331843 Convert global responses variable in dispatch_test to C11 atomics 2020-01-14 13:12:13 +01:00
Ondřej Surý
6afa99362a Remove duplicate INSIST checks for isc_refcount API
This commits removes superfluous checks when using the isc_refcount API.

Examples of superfluous checks:

1. The isc_refcount_decrement function ensures there was not underflow,
   so this check is superfluous:

    INSIST(isc_refcount_decrement(&r) > 0);

2 .The isc_refcount_destroy() includes check whether the counter
   is zero, therefore this is superfluous:

    INSIST(isc_refcount_decrement(&r) == 1 && isc_refcount_destroy(&r));
2020-01-14 13:12:13 +01:00
Ondřej Surý
e711b0304f Convert more reference counting to isc_refcount API 2020-01-14 13:12:13 +01:00
Ondřej Surý
7c3e342935 Use isc_refcount_increment0() where appropriate 2020-01-14 13:12:13 +01:00
Ondřej Surý
9ce3254a1b Improve code style when checking old references values 2020-01-14 13:12:13 +01:00
Ondřej Surý
7dfc092f06 Use C11 atomics for nfctx, kill unused dns_resolver_nrunning() 2020-01-14 13:12:13 +01:00
Ondřej Surý
5208505f03 Use dns_keytable_attachkeynode() and switch to C11 atomics for .active_nodes 2020-01-14 13:12:13 +01:00
Ondřej Surý
fbf9856f43 Add isc_refcount_destroy() as appropriate 2020-01-14 13:12:13 +01:00