Commit Graph

3273 Commits

Author SHA1 Message Date
Ondřej Surý
1eb5a77baa Set WarningLevel to Level1 for Release, treat warnings as errors
Our vcxproj files set the WarningLevel to Level3, which is too verbose
for a code that needs to be portable.  That basically leads to ignoring
all the errors that MSVC produces.  This commits downgrades the
WarningLevel to Level1 and enables treating warnings as errors for
Release builds.  For the Debug builds the WarningLevel got upgraded to
Level4, and treating warnings as errors is explicitly disabled.

We should eventually make the code clean of all MSVC warnings, but it's
a long way to go for Level4, so it's more reasonable to start at Level1.

For reference[1], these are the warning levels as described by MSVC
documentation:

  * /W0 suppresses all warnings. It's equivalent to /w.
  * /W1 displays level 1 (severe) warnings. /W1 is the default setting
    in the command-line compiler.
  * /W2 displays level 1 and level 2 (significant) warnings.
  * /W3 displays level 1, level 2, and level 3 (production quality)
    warnings. /W3 is the default setting in the IDE.
  * /W4 displays level 1, level 2, and level 3 warnings, and all level 4
    (informational) warnings that aren't off by default. We recommend
    that you use this option to provide lint-like warnings. For a new
    project, it may be best to use /W4 in all compilations. This option
    helps ensure the fewest possible hard-to-find code defects.
  * /Wall displays all warnings displayed by /W4 and all other warnings
    that /W4 doesn't include — for example, warnings that are off by
    default.
  * /WX treats all compiler warnings as errors. For a new project, it
    may be best to use /WX in all compilations; resolving all warnings
    ensures the fewest possible hard-to-find code defects.

1. https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level?view=vs-2019

(cherry picked from commit 789d253e3d)
2020-04-16 08:12:39 +02:00
Ondřej Surý
ff814288af Fix 'Dead nested assignment' from scan-build-10
This is the warning:

In file included from print_test.c:47:
./../print.c:203:9: warning: Although the value stored to 'neg' is used in the enclosing expression, the value is never actually read from 'neg'
                dot = neg = space = plus = left = zero = alt = h = l = q = z = 0;
                      ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
2020-03-26 13:52:28 +01:00
Tinderbox User
4236979e90 Adjust lib/isc/api version
The libisc LIBINTERFACE bump for 9.11.17 is unnecessary.
A lot of headers were altered but the ABI tool did not report anything.
Trust the ABI tool on this and decrement LIBINTERFACE and increment
LIBREVISION.
2020-03-20 10:32:32 +01:00
Tinderbox User
d050ec2429 prep 9.11.17
Bumped the version file and added release line in CHANGES.

API files:
- lib/bind9/api:
  No changes because only changes in comments.
- lib/dns/api:
  Increment LIBINTERFACE because of the added field structure in
  dns_struct_update.
- lib/isc/api:
  Increment LIBINTERFACE because of the PKCS#11 replacement.
- lib/isccc/api:
  No changes because no source code changes.
- lib/isccfg/api:
  Increment LIBREVISION because of minor source code changes.
- lib/lwres/api:
  No changes because no source code changes.

I decided no changes to README.md or the release notes were necessary.

Perflab graphs look sane.
2020-03-20 10:31:29 +01:00
Mark Andrews
0ddfa675e4 Just return tv_sec field 2020-03-18 06:36:10 +00:00
Ondřej Surý
5ae4d3d94a Add C11 localtime_r and gmtime_r shims for Windows
On Windows, C11 localtime_r() and gmtime_r() functions are not
available.  While localtime() and gmtime() functions are already thread
safe because they use Thread Local Storage, it's quite ugly to #ifdef
around every localtime_r() and gmtime_r() usage to make the usage also
thread-safe on POSIX platforms.

The commit adds wrappers around Windows localtime_s() and gmtime_s()
functions.

NOTE: The implementation of localtime_s and gmtime_s in Microsoft CRT
are incompatible with the C standard since it has reversed parameter
order and errno_t return type.

(cherry picked from commit 08f4c7d6c0)
2020-03-17 15:45:35 -07:00
Evan Hunt
1dbd238c15 fix a pointer-to-int cast error
(cherry picked from commit 6b76646037)
2020-03-17 13:16:07 -07:00
Mark Andrews
8fce52189e Fix lists of installed header files 2020-03-06 13:09:47 +11:00
Michał Kępień
ae7c0cca89 Fix cppcheck 1.89 warnings
cppcheck 1.89 enabled certain value flow analysis mechanisms [1] which
trigger null pointer dereference false positives that were previously
not reported.  It seems that cppcheck no longer treats at least some
REQUIRE() assertion failures as fatal, so add extra assertion macro
definitions to lib/isc/include/isc/util.h that are only used when the
CPPCHECK preprocessor macro is defined; these definitions make cppcheck
1.89 behave as expected.

There is an important requirement for these custom definitions to work:
cppcheck must properly treat abort() as a function which does not
return.  In order for that to happen, the __GNUC__ macro must be set to
a high enough number (because system include directories are used and
system headers compile attributes away if __GNUC__ is not high enough).
__GNUC__ is thus set to the major version number of the GCC compiler
used, which is what that latter does itself during compilation.

[1] aaeec462e6

(cherry picked from commit abfde3d543)
2020-03-04 12:41:01 +01:00
Ondřej Surý
5edc8b5338 Use standard PKCS#11 standard error codes instead of custom error codes
* CKR_CRYPTOKI_ALREADY_INITIALIZED: This value can only be returned by
  `C_Initialize`. It means that the Cryptoki library has already been
  initialized (by a previous call to `C_Initialize` which did not have a
  matching `C_Finalize` call).

* CKR_FUNCTION_NOT_SUPPORTED: The requested function is not supported by this
  Cryptoki library. Even unsupported functions in the Cryptoki API should have a
  "stub" in the library; this stub should simply return the value
  CKR_FUNCTION_NOT_SUPPORTED.

* CKR_LIBRARY_LOAD_FAILED: The Cryptoki library could not load a dependent
  shared library.

(cherry picked from commit f6922d6e78)
2020-03-02 11:01:05 +01:00
Ondřej Surý
4b9cdbaf7e Replace the OASIS PKCS#11 header file with one from p11-kit
The OASIS pkcs11.h header has a restrictive license.  Replace the
pkcs11.h pkcs11f.h and pkcs11t.h headers with pkcs11.h from p11-kit.

For source distribution, the license for the OASIS headers itself
doesn't pose any licensing problem when combined with MPL license, but
it possibly creates problem for downstream distributors of BIND 9.

(cherry picked from commit c47fad2431)
2020-03-02 10:43:45 +01:00
Evan Hunt
191b616579 fix additional spelling errors 2020-02-24 22:04:43 -08:00
Evan Hunt
e63223332c fix spelling errors reported by Fossies. 2020-02-21 14:09:59 -08:00
Tinderbox User
aa55ef6c43 prep 9.11.16 2020-02-12 15:37:33 +00:00
Ondřej Surý
f71a8d1120 Convert all atomic operations in isc_rwlock to sequentially-consistent ordering
The memory ordering in the rwlock was all wrong, I am copying excerpts
from the https://en.cppreference.com/w/c/atomic/memory_order#Relaxed_ordering
for the convenience of the reader:

  Relaxed ordering

  Atomic operations tagged memory_order_relaxed are not synchronization
  operations; they do not impose an order among concurrent memory
  accesses. They only guarantee atomicity and modification order
  consistency.

  Sequentially-consistent ordering

  Atomic operations tagged memory_order_seq_cst not only order memory
  the same way as release/acquire ordering (everything that
  happened-before a store in one thread becomes a visible side effect in
  the thread that did a load), but also establish a single total
  modification order of all atomic operations that are so tagged.

Which basically means that we had no or weak synchronization between
threads using the same variables in the rwlock structure.  There should
not be a significant performance drop because the critical sections were
already protected by:

  while(1) {
    if (relaxed_atomic_operation) {
      break;
    }
    LOCK(lock);
    if (!relaxed_atomic_operation) {
      WAIT(sem, lock);
    }
    UNLOCK(lock)l
  }

I would add one more thing to "Don't do your own crypto, folks.":

  - Also don't do your own locking, folks.

As part of this commit, I have also cleaned up the #ifdef spaghetti,
and fixed the isc_atomic API usage.
2020-02-11 21:20:14 +01:00
Ondřej Surý
542517b194 Make isc_rwlock.c thread-safe
The ThreadSanitizer found several possible data races in our rwlock
implementation.  This commit convert .spins and .write_granted fields
to atomic.

(cherry picked from commit 1da0994ea4)
2020-02-11 20:05:51 +01:00
Ondřej Surý
699bda8de7 Clean the ENTER/EXIT/NOTICE debugging from production code
(cherry picked from commit 5b448996e5)
2020-02-08 11:46:37 -08:00
Ondřej Surý
f2c5bdda21 Refactor parts of isc_httpd and isc_httpd for better readability and safety
(cherry picked from commit 9643a62dd5)
2020-02-08 11:46:37 -08:00
Mark Andrews
e5522d114b add ISC_MAGIC and reference counting to httpd and httpdmgr
(cherry picked from commit 7c3f419d66)
2020-02-08 11:37:25 -08:00
Matthijs Mekking
ea477e114b mem.c: delay assignment until after REQUIRE 2020-02-08 06:32:42 -08:00
Matthijs Mekking
c8959c0e3a Check for basic blocks not NULL 2020-02-08 06:32:42 -08:00
Mark Andrews
39cb4dc6c9 delay assignment until after REQUIRE
(cherry picked from commit c65c06301c)
2020-02-08 06:32:42 -08:00
Mark Andrews
12cda20aa2 simplify ISC_LIKELY/ISC_UNLIKELY for CPPCHECK
(cherry picked from commit 6c2e138d7a)
2020-02-08 06:32:42 -08:00
Mark Andrews
26caad3c12 simplify RUNTIME_CHECK for cppcheck
(cherry picked from commit 668a972d1e)
2020-02-08 06:32:42 -08:00
Michal Nowak
0e284831ce Windows: Prevent tools from clashing with named in system tests
In system tests on Windows tool's local port can sometimes clash with
'named'. On Unix the system is poked for the minimal local port,
otherwise is set to 32768 as a sane minimum. For Windows we don't
poke but set a hardcoded limit; this change aligns the limit with
Unix and changes it to 32768.

(cherry picked from commit ed7fe5fae3b22d136f0a5a92ea3b67536b10a5ce)
2020-02-05 11:07:33 +00:00
Tinderbox User
296ccbf479 prep 9.11.15
Update the API files.
- lib/dns:
  - struct resolver has added elements, this is an interface change
    and thus LIBINTERFACE is incremented, and LIBREVISION is reset.
  - Since this also means an interface change since the last public
    release, also reset LIBAGE.
- lib/isc:
  - The library source code changed, so increment LIBREVISION.
- lib/isccfg:
  - The library source code changed, so increment LIBREVISION.

Update other files:
- No changes needed to the README, this is a small bugfix release.
- Fix a bad version xml:id in the release notes.
2020-01-27 11:10:16 -08:00
Michał Kępień
daade37977 Handle catopen() errors
musl libc's implementation of catgets() crashes when its first argument
is -1 instead of a proper message catalog descriptor.  Prevent that from
happening by making isc_msgcat_get() return the default text if the
prior call to catopen() returns an error.
2020-01-13 14:03:11 +01:00
Mark Andrews
939f2fa2f5 formally discard return value 2020-01-13 05:07:13 +00:00
Mark Andrews
261c84d91d fix variable name in conditional block 2019-12-19 09:27:44 +11:00
Mark Andrews
7c94d2cd7d acquire task lock before calling push_readyq for task->flags access 2019-12-12 22:54:15 +00:00
Tinderbox User
ed6da5ec3d prep 9.11.14 2019-12-12 05:01:05 +00:00
Ondřej Surý
e50abe8a70 Cleanup the isc_stats code 2019-12-04 19:39:57 -03:00
Diego Fronza
8680c367cd Fix tcp-higwater stats for some specific platforms
The previous code had some errors that would be triggered on platforms
without stdatomics but with support for xadd assembly instruction.

The major error was combining two uint32_t values from the
multifield atomic structure using a logical AND '&&' instead of a
bitwise OR '|'.

Some preprocessor rules were redundant and thus were simplified,
regarding the definition of ISC_STATS_USEMULTIFIELDS macro.

Correctly changed rwlock type to read on isc_stats_get_counter.
2019-12-04 19:39:56 -03:00
Evan Hunt
99203103b7 Merge tag 'v9_11_13' into merge-v9_11_13 2019-11-20 13:43:34 -08:00
Ondřej Surý
d2c86b2159 Internally, use {PATH,NAME}_MAX instead of ISC_DIR_{PATH,NAME}MAX 2019-11-12 09:31:40 +01:00
Samuel Thibault
88061c2acb hurd: Fix build
Move PATH_MAX, NAME_MAX, IOV_MAX default definitions to the common
<isc/platform.h>.

(cherry picked from commit d10fbdec84)
2019-11-12 09:22:15 +01:00
Tinderbox User
336d24089b prep 9.11.13 2019-11-06 21:26:36 +00:00
Michał Kępień
4876a88fc0 Do not use <sys/sysctl.h> on Linux
glibc 2.30 deprecated the <sys/sysctl.h> header [1].  However, that
header is still used on other Unix-like systems, so only prevent it from
being used on Linux, in order to prevent compiler warnings from being
triggered.

[1] https://sourceware.org/ml/libc-alpha/2019-08/msg00029.html

(cherry picked from commit 65a8b53bd0)
2019-11-06 21:11:20 +01:00
Ondřej Surý
55b0da1381 Backport isc_quota_getused() function 2019-11-06 12:54:40 +01:00
Ondřej Surý
e8bf3c60f2 Avoid an extra atomic_load() call 2019-11-06 12:54:40 +01:00
Diego Fronza
4ad2ab54cd Added TCP high-water statistics variable
This variable will report the maximum number of simultaneous tcp clients
that BIND has served while running.

It can be verified by running rndc status, then inspect "tcp high-water:
count", or by generating statistics file, rndc stats, then inspect the
line with "TCP connection high-water" text.

The tcp-highwater variable is atomically updated based on an existing
tcp-quota system handled in ns/client.c.

(cherry picked from commit 66fe8627de)
2019-11-06 12:54:40 +01:00
Diego Fronza
5a9c5166ce Add functions for collecting high-water counters
Add {isc,ns}_stats_{update_if_greater,get_counter}() functions that
are used to set and collect high-water type of statistics.

(cherry picked from commit a544e2e300)
2019-11-06 12:35:33 +01:00
Diego Fronza
e4ebeff0e4 Change the isc_statscounter_t type from int to C99 int_fast64_t type
For TCP high-water work, we need to keep the used integer types widths
in sync.

Note: int_fast32_t is used on WIN32 platform
(cherry picked from commit 0fc98ef2d5)
2019-11-06 12:35:33 +01:00
Tinderbox User
5dfdc818d2 Merge branch 'v9_11_12' into v9_11 2019-10-24 05:58:38 +00:00
Michał Kępień
cacba609c7 Suppress cppcheck 1.89 false positive
cppcheck 1.89 emits a false positive for lib/isc/sha1.c:

    lib/isc/sha1.c:273:16: error: Uninitialized variable: block [uninitvar]
     (void)memmove(block, buffer, 64);
                   ^
    lib/isc/sha1.c:272:10: note: Assignment 'block=&workspace', assigned value is <Uninit>
     block = &workspace;
             ^
    lib/isc/sha1.c:273:16: note: Uninitialized variable: block
     (void)memmove(block, buffer, 64);
                   ^

This message started appearing with cppcheck 1.89 [1], but it will be
gone in the next release [2], so just suppress it for the time being.

[1] af214e8212

[2] 2595b82634
2019-10-17 11:13:30 +02:00
Mark Andrews
42f998ee14 Detect partial prefixes / incomplete IPv4 address in acls.
(cherry picked from commit fb87e669fb)
2019-10-14 22:12:16 +11:00
Mark Andrews
d2c51b9c4b Address cppcheck reports
(cherry picked from commit fcebc4f15b)
2019-10-04 14:34:21 +10:00
Ondřej Surý
b06f36a726 lib/isc/include/isc/stdatomic.h: Suppress preprocessorErrorDirective error from Cppcheck 2019-10-03 14:21:47 +02:00
Ondřej Surý
61b3ab76a5 lib/isc/random.c: Suppress preprocessorErrorDirective error from Cppcheck 2019-10-03 14:21:47 +02:00
Ondřej Surý
d26c36a338 Remove randomly scattered additional style check suppressions that caused unmatchedSuppression
(cherry picked from commit a0d3614a60)
2019-10-03 14:21:47 +02:00