Skip to content

fix: silence -Wnonnull-compare and Botan FFI deprecation warnings - #2446

Closed
ronaldtse wants to merge 1 commit into
mainfrom
fix/build-warnings
Closed

fix: silence -Wnonnull-compare and Botan FFI deprecation warnings#2446
ronaldtse wants to merge 1 commit into
mainfrom
fix/build-warnings

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Fixes two build-warning classes reported in the v0.18.1 release build (GCC).

1. -Wnonnull-compare in src/librekey/rnp_key_store.cpp

RNP_LOG_KEY(msg, &srckey) expanded to if (!(&srckey)), but &srckey is the address of a Key& reference and is provably non-null, so GCC flagged every such call site. Added an RNP_LOG_KEY_NN variant (no null check) in src/lib/logging.h and switched all &srckey call sites to it. Nullable-pointer sites (primary, added_key) keep the null-checking RNP_LOG_KEY. Verified there are no remaining RNP_LOG_KEY(..., &ref) call sites in the tree.

2. -Wdeprecated-declarations in src/lib/crypto/ec.cpp and src/lib/crypto/eddsa.cpp

botan_privkey_x25519_get_privkey, botan_pubkey_x25519_get_pubkey, and botan_privkey_ed25519_get_privkey are deprecated in Botan 3.x. Switched to the generic botan_privkey_view_raw / botan_pubkey_view_raw API (available since Botan 3.6) under a BOTAN_VERSION_CODE >= 3.6.0 guard, keeping the legacy calls for older Botan (2.x and 3.0–3.5, where the helpers are not deprecated and view_raw does not exist). A small length-checked view callback (rnp_botan_view_bin) and descriptor (rnp_botan_view_buf) live in src/lib/crypto/botan_utils.hpp; the per-site descriptors are declared inside the #if so they don't trigger -Wunused-variable on older Botan.

A codebase-wide sweep confirmed the remaining deprecated Botan FFI calls (botan_key_wrap3394/botan_key_unwrap3394 in ecdh.cpp, the _enc SM2 loaders) are already behind CRYPTO_BACKEND_BOTAN3 guards or use the non-deprecated overloads, and that ed448/x448 paths do not use the deprecated getters.

Notes

  • Builds against Botan 2.x and 3.0–3.5 are unaffected (legacy call paths retained).
  • The pre-existing Botan 3.12 native C++ API breakage in ec.cpp (around Botan::EC_Group::from_name, under ENABLE_CRYPTO_REFRESH) is unrelated to these warning classes and intentionally left out of scope.

Test plan

  • Configured with -DCRYPTO_BACKEND=botan3 against Botan 3.12; librnp-obj, rnpkeys, and rnp build with zero warnings/errors (Apple Clang 15).
  • ec.cpp, eddsa.cpp, rnp_key_store.cpp compile clean.
  • Runtime: generated an Ed25519 primary + Curve25519 ECDH subkey (expert mode option 22) — exercises all three migrated view_raw call sites.
  • Sign/verify with the Ed25519 key passes; encrypt/decrypt round-trip through the Curve25519 subkey passes.
  • CI (Linux/GCC) confirms -Wnonnull-compare and -Wdeprecated-declarations are gone for these files.

Two build-warning classes from the v0.18.1 release build:

* rnp_key_store.cpp passed &srckey (address of a Key reference, which is
  provably non-null) to RNP_LOG_KEY, whose null guard then tripped
  -Wnonnull-compare under GCC. Add an RNP_LOG_KEY_NN variant without the
  null check and use it for every &srckey call site; nullable pointers
  (primary/added_key) keep the null-checking macro.

* ec.cpp and eddsa.cpp used botan_{privkey,pubkey}_*_get_* helpers
  deprecated in Botan 3.x. Use the generic botan_*_view_raw API
  (available since Botan 3.6) when available, keeping the legacy calls
  for older Botan. A small length-checked view callback is added to
  botan_utils.hpp.
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.37%. Comparing base (975b67c) to head (01bbed9).

Files with missing lines Patch % Lines
src/librekey/rnp_key_store.cpp 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2446      +/-   ##
==========================================
- Coverage   85.37%   85.37%   -0.01%     
==========================================
  Files         126      126              
  Lines       22790    22775      -15     
==========================================
- Hits        19458    19445      -13     
+ Misses       3332     3330       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ronaldtse
ronaldtse requested review from antonsviridenko and ni4 July 31, 2026 16:19
@ronaldtse

Copy link
Copy Markdown
Contributor Author

Closing — superseded by #2448 which migrates Botan backend to FFI, resolving the deprecation warnings this PR was silencing. Combined to reduce review overhead.

@ronaldtse ronaldtse closed this Aug 5, 2026
ronaldtse added a commit that referenced this pull request Aug 5, 2026
…s PR

Merges the -Wnonnull-compare fix (RNP_LOG_KEY_NN macro + rnp_key_store
usage) and the compile-time-warnings.adoc policy doc from the now-closed
#2446 and #2428 into this PR, since the FFI migration naturally resolves
the deprecation warnings those PRs were patching.

Reduces review overhead: one PR covers the FFI migration + the warning
policy + the nonnull-compare fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant