fix: null-deref when dbgKey unset under HELIB_DEBUG (#501)#523
Open
BAder82t wants to merge 1 commit intohomenc:masterfrom
Open
fix: null-deref when dbgKey unset under HELIB_DEBUG (#501)#523BAder82t wants to merge 1 commit intohomenc:masterfrom
BAder82t wants to merge 1 commit intohomenc:masterfrom
Conversation
Several debug-only paths dereference *dbgKey / *dbgEa unconditionally, segfaulting when setupDebugGlobals() was never called (e.g. the bundled BGV_binary_arithmetic example under Ctxt::multiplyBy - > checkNoise) Guard each debug block with a null check, matching the existing pattern in extractDigits.cpp and debugging.cpp Closes homenc#501
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.
Summary
Fixes segfault reported in #501.
When HElib is compiled with `HELIB_DEBUG` and the user program does not call `setupDebugGlobals(&sk, ...)`, the global `dbgKey` / `dbgEa` remain `nullptr`. Several debug-only call sites dereference `*dbgKey` / `*dbgEa` unconditionally, causing a segfault. The reporter hit this running the bundled `BGV_binary_arithmetic` example:
```
SEGV at keys.cpp:273 PubKey::getContext(this=0x0)
<- SecKey::Decrypt(this=0x0, ...) keys.cpp:1338
<- embeddingLargestCoeff debugging.cpp:60
<- realToEstimatedNoise debugging.cpp:30
<- checkNoise debugging.cpp:50
<- Ctxt::multiplyBy Ctxt.cpp:1772
```
Fix
Guard every `*dbgKey` / `*dbgEa` dereference with an explicit null check, matching the existing pattern already used in `extractDigits.cpp` and `debugging.cpp`. Release builds (`HELIB_DEBUG` off) are unchanged.
Call sites touched:
Verification
Minimal BGV repro (single `Ctxt::multiplyBy`, no `setupDebugGlobals` call, built with `-DHELIB_DEBUG -fsanitize=address`):
Closes
#501