BUG: maxfwd module incorrectly decrements header twice if the max-forwards… #3511
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
Solves an issue where using the
maxfwd
module functionmf_process_maxfwd_header
can incorrectly double decrement the header value ifsipmsg_validate
function with flagh
is called before calling the aforementioned functionDetails
This is a bug fix which should prevent future issues when using maxfwd which assumes that the
parsed
value inhdr_field
will only ever be used by the maxfwds module which can cause an incorrect double decrement of the header value if some other module was the set theparsed
memory to something other thannull
Solution
The
maxfwd
module has two macros defined which store and fetch the value of theparsed
property of themaxforwards
header in the SIP Message, when storing it stores it adding 1 to the value and when fetching it subtracts 1 from the value. This is because this memory block is a void* and 0 represents a null pointer.A problem arises when using
sipmsg_validate
to validate the headers, it will parse the value of the header into theparsed
field and when maxfwds checks for the value it assumes it has already been added by the module which adds 1 to the value so when it fetches the value it will then subtract 1 from it causing the double decrement of the value.The solution is a partial rewrite of the module where the addition and subtraction logic in the macro is removed in favour of assuming a value of 0 and a null value act exactly the same anyway so when the header is parsed and the value is 0 then we can just try and parse it from the body again anyway and end up with a value of 0 again but if the value is greater than 0 then we can just fetch the value in the parsed field and return, the trim logic which gets the string representation is called in all cases before checking if the value exists in the parsed header and/or fetching it. We can assume that if we get to trim stage then the header has a body at this stage
Compatibility
No compatibility issues, in fact it fixes a compatibility issue with sipmsgops and maxfwds