BUG: Fix cdfbin's argument range check, which could never fire - #114
Open
hjmjohnson wants to merge 2 commits into
Open
hjmjohnson wants to merge 2 commits into
hjmjohnson wants to merge 2 commits into
Conversation
cdfbin() validates its `which` selector like this:
if(!(*which < 1 && *which > 4)) goto S30;
A value cannot be both less than 1 and greater than 4, so the condition
is always false, the negation is always true, and the jump to S30 is
always taken -- skipping the entire range check. gcc reports it as
-Wlogical-op, "logical 'and' of mutually exclusive tests is always
false".
The ten sibling functions in this file all spell the same guard with
`||`:
cdfbet 1527: if(!(*which < 1 || *which > 4)) goto S30;
cdfchi 2255: if(!(*which < 1 || *which > 3)) goto S30;
cdfchn 2553: if(!(*which < 1 || *which > 4)) goto S30;
... 7 more
so this is a single-character typo rather than an intentional deviation.
The effect is visible from the public API. cdfbin is declared in the
installed nifticdf.h, and its contract is that an out-of-range input sets
*status to -1 and *bound to the limit that was violated. Calling it with
which = 9:
before: status=999 bound=-999 (both left as the caller set them)
after: status=-1 bound=4 (the documented error return)
Before the fix the caller has no indication anything was wrong and the
function proceeds to compute with an unhandled selector.
(cherry picked from commit 5c63a01)
The range check is reachable from the installed nifticdf.h, so assert the documented contract directly: which=9 and which=0 must set *status to -1 and *bound to the limit that was violated. A which=1 call is asserted to still return status 0, so a guard that rejected everything would not pass. (cherry picked from commit 493a317)
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.
Re-submission of #39, reverted from
masteron 2026-09-24 so it can bereviewed before merging. Content is unchanged from the original.
Base:
master. Independent: nothing has to land before it.Commits
Ordering for all the re-submitted work is tracked in #84.