Repository navigation
crypto: declare the backends' canaries constinit in place of four clang-tidy suppressions - #15
Merged
Merged
Conversation
…-dynamic-static-initializers reads, in place of four suppressions Each canary's declaration (BearSSL, libsodium, ctaes, libsecp256k1) is a namespace-scope variable without an initialiser, which bugprone-dynamic-static-initializers reports in a header as one that may be dynamically initialised. Its definition, src/canary_<name>.c, is a C constant: its initialisation is static. constinit on the declaration states that fact, which the check reads, so the four NOLINTNEXTLINE are gone. The two MSVC tests that define a canary in C++ repeat constinit on that initialising declaration, as the standard asks.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The four link-time canaries of webcpp::crypto's backends (BearSSL, libsodium, ctaes, libsecp256k1) are declared
constinitin their headers, in place of the fourNOLINTNEXTLINE(bugprone-dynamic-static-initializers)that suppressed the finding. The two MSVC tests that define a canary in C++ (test/msvc/canary_two_files,test/msvc/canary_secp256k1_two_files) repeatconstiniton that initialising declaration.Why
trystero's port reported
bugprone-dynamic-static-initializersatbackends/secp256k1.hpp(extern "C" const char WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY;) in its Emscripten units: its pinned crypto predates the suppression main gained in 9c9bbc2. The cause is the declaration itself: a namespace-scope variable of static storage in a header, with no initialiser in any C++ translation unit, which the check cannot tell from one that is dynamically initialised (it fires on every global-storage variable whose initialiser it cannot evaluate, a missing one included). Its definition issrc/canary_<name>.c's= 0, a C constant: its initialisation is static, never dynamic.Rulings
constiniton the declaration states the fact the check asks about (the variable is constant-initialised), and the check honours it. It removes all four suppressions, not only libsecp256k1's: the four canaries share the one declaration form, and leaving three suppressed beside one stated would make them differ for no reason.constinitacross languages. [dcl.constinit] asks that the initialising declaration also carryconstinit. Where that declaration is C++ (the two MSVC tests), it does. Where it issrc/canary_<name>.c, C has noconstinitand no dynamic initialisation at all, so the promise holds by construction.NOLINT(the finding is a false positive, but a suppression is the last resort when the code cannot say why, and hereconstinitsays it); turning the canaries into functions (would change the C side, the link-time contract and the guide, for no gain over a volatile byte load).Verified
test/secp256k1_keys_test.cppwith em++'s--cflagsreports the finding at the declaration once the suppression is removed; withconstinit, it is clean.constinitamong them; the only failures are the lane's known Boost.JSON silent stops of translation units without exceptions (no diagnostic), one of which,async_p256_testwithout exceptions, the lane now lists.