Fix _Bool functions that silently discard -1 error returns - #424
Merged
thegushi merged 1 commit intoJul 22, 2026
Merged
Conversation
dkim_sig_hdrlistok() and dkimf_parsehandler() are declared to return _Bool but use a tri-state contract (TRUE/FALSE/-1). In C99/C11, a _Bool-returning function implicitly converts any nonzero return value to 1 at the return statement, so `return -1;` actually returns TRUE to the caller. For dkim_sig_hdrlistok(), this means a DKIM_MALLOC failure is silently treated as "header list OK" instead of propagating DKIM_STAT_NORESOURCE. For dkimf_parsehandler(), this means an invalid value for any On-* handling directive in the config file populates the error buffer but the invalid-value branch never causes config loading to fail, since `!dkimf_parsehandler(...)` is false whether the function returns TRUE or (as it actually does after the _Bool conversion) what should have been -1. Fixed by changing both functions to return int, and updating the dkimf_parsehandler() call sites to check `!= TRUE` instead of `!`, since FALSE and -1 both need to trip the error path. cppcheck flags the caller-side dead code directly: dkim.c:2170: Condition 'hstatus==-1' is always false
2 tasks
thegushi
added a commit
that referenced
this pull request
Jul 22, 2026
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
cppcheck static analysis turned up two instances of the same root cause: a function declared
static _Boolthat doesreturn -1;on an error path. In C99/C11, a_Bool-returning function implicitly converts any nonzerointexpression to1(TRUE) at thereturnstatement, so these functions actually returnTRUE, not-1, defeating callers that check for a tri-state (TRUE/FALSE/-1) contract.dkim_sig_hdrlistok()(libopendkim/dkim.c): aDKIM_MALLOCfailure is silently treated as "header list OK" instead of propagatingDKIM_STAT_NORESOURCE. cppcheck confirms the caller-side dead code:dkim.c:2170: Condition 'hstatus==-1' is always false.dkimf_parsehandler()(opendkim/opendkim.c): an invalid value for anyOn-*handling directive in the config file populates the error buffer, but the config-load call sites (!dkimf_parsehandler(...)) never see the failure, so config loading proceeds as if the directive were valid.I grepped every
_Bool-returning function in the tree forreturn -1;inside its body and confirmed these are the only two instances of the idiom.Changes
static _Booltostatic int, keeping their existing TRUE(1)/FALSE(0)/-1 return values as literal ints.dkimf_parsehandler()call sites indkimf_config_load()from!dkimf_parsehandler(...)todkimf_parsehandler(...) != TRUE, since both FALSE and -1 need to trip the error path.dkim_sig_hdrlistok()'s one call site already used anintlocal for the result, so no caller change was needed there.Test plan
autoreconf -fi && ./configure && gmakebuilds cleangmake check: 174/174 tests pass