Repository navigation
Fix one-byte stack overflow in myIpAddress() with an over-long client IP - #270
Merged
Merged
Conversation
pacparser_setmyip() accepted strings of up to INET6_ADDRSTRLEN (46) characters, but my_ip() copies the value into an INET6_ADDRSTRLEN-byte stack buffer, so a 46-character value overflowed it by the terminating NUL. INET6_ADDRSTRLEN already counts the NUL, so no valid IP address is that long: reject such values in pacparser_setmyip(), and size my_ip()'s buffer to match my_ip_buf. Add tests that the longest valid IP is accepted and returned by myIpAddress(), and that a longer value is rejected. Reported by Tushar98644.
- The Python binding ignored pacparser_setmyip()'s return value, so a rejected client IP was silently dropped. Raise ValueError instead. - Size my_ip_buf for the longest textual IP address (46 bytes with NUL) instead of INET6_ADDRSTRLEN, which is 65 on Windows, so the limit is the same on every platform. - Return my_ip_buf directly from my_ip() and my_ip_ex() instead of copying it to a stack buffer first. - Report the rejection through print_error(), so it honours pacparser_set_error_printer(). - Tests: check the error message in the shell test, quote and clean up the temp PAC file, and add a Python test for setmyip().
|
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.



pacparser_setmyip()accepted client IPs of up toINET6_ADDRSTRLEN(46) characters.my_ip()copies the value into a 46-byte stack buffer, so a 46-character value overflowed it by one byte (the terminating NUL).Only values that aren't IP addresses can trigger it:
INET6_ADDRSTRLENalready counts the NUL, so the longest valid IP is 45 characters. The value comes from the embedding application orpactester -c, not from PAC files.Changes:
pacparser_setmyip()now rejects values that don't fit inmy_ip_buf, which is sized for the longest textual IP address (45 characters plus NUL). The fixed size replacesINET6_ADDRSTRLEN, which is 65 on Windows, so the limit is the same on every platform.my_ip()andmy_ip_ex()returnmy_ip_bufdirectly instead of copying it to a stack buffer first.print_error(), so it goes throughpacparser_set_error_printer().setmyip()raisesValueErrorwhen the IP is rejected. It used to ignore the result.tests/runtests.shandtests/runtests.py, the longest valid IP (ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255) is accepted and returned bymyIpAddress(), and a 46-character value is rejected (with the error message checked in the shell test andValueErrorin Python).Testing:
NO_INTERNET=1 make -C srcandmake -C src pymodpass, including the new tests.stack-buffer-overflow ... in my_iponmainand runs cleanly with this change.Reported by Tushar98644.