Repository navigation
Fix XPath mod SIGFPE on zero divisor, and xml_diff() with NULL first tree - #703
Open
khromenokroman wants to merge 3 commits into
Open
khromenokroman wants to merge 3 commits into
khromenokroman wants to merge 3 commits into
Conversation
xp_numop() computed mod as ((int)n1)%((int)n2). If the divisor truncates to 0, eg "1 mod 0" or "1 mod 0.5", the process is killed by SIGFPE. Such an expression may come from YANG must/when statements evaluated on user data, or from an XPath filter in a NETCONF get request, so it can crash the backend. XPath 1.0 section 3.5 defines mod on numbers (floating point) as the remainder from a truncating division, ie fmod(). Use fmod(), which also returns correct results for non-integer operands (5.5 mod 2 = 1.5, previously 1) and NaN for a zero divisor, as div does.
If the first tree is NULL, all of the second tree is new, but x0 (NULL) was appended to the second vector instead of x1 (copy-paste error from the x1 == NULL case above).
This branch has not been deployed
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.
@olofhagsand Hello
Description:
Two independent small fixes.
1. XPath
modcrashed with SIGFPExp_numop()computedmodas((int)n1)%((int)n2). If the divisortruncates to 0, e.g.
1 mod 0or1 mod 0.5, the process is killed bySIGFPE.
Such expressions can come from YANG
must/whenstatements evaluated onuser data, or from an XPath filter in a NETCONF
<get>, so a client cancrash the backend. Example:
XPath 1.0 section 3.5 defines
modon numbers (floating point) as theremainder from a truncating division, i.e.
fmod(). Usingfmod():div), so themustabove simplyfails validation;
5.5 mod 2= 1.5(previously 1).
5 mod 2,5 mod -2,-5 mod 25.5 mod 21 mod 01 mod 0.5must "(../a mod ../b) = 0", b=0Failed MUST xpath2.
xml_diff()with NULL first treeIf
x0 == NULL, the whole second tree is new, butx0(NULL) was appendedto the
secondvector instead ofx1(copy-paste from thex1 == NULLcase just above). Callers iterating
secondwould get a NULL node.Testing
test/test_xpath.sh: addedmodcases including zero and non-integerdivisors (values from XPath 1.0 3.5 examples).
clixon_util_xpathand a standalonevalidation program against master and this branch.