Skip to content

Fix one-byte stack overflow in myIpAddress() with an over-long client IP - #270

Merged
manugarg merged 3 commits into
mainfrom
fix-setmyip-length
Nov 10, 2026
Merged

manugarg merged 3 commits into
mainfrom
fix-setmyip-length

Conversation

@manugarg

@manugarg manugarg commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

pacparser_setmyip() accepted client IPs of up to INET6_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_ADDRSTRLEN already counts the NUL, so the longest valid IP is 45 characters. The value comes from the embedding application or pactester -c, not from PAC files.

Changes:

  • pacparser_setmyip() now rejects values that don't fit in my_ip_buf, which is sized for the longest textual IP address (45 characters plus NUL). The fixed size replaces INET6_ADDRSTRLEN, which is 65 on Windows, so the limit is the same on every platform.
  • my_ip() and my_ip_ex() return my_ip_buf directly instead of copying it to a stack buffer first.
  • The rejection is reported through print_error(), so it goes through pacparser_set_error_printer().
  • The Python setmyip() raises ValueError when the IP is rejected. It used to ignore the result.
  • Tests: in tests/runtests.sh and tests/runtests.py, the longest valid IP (ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255) is accepted and returned by myIpAddress(), and a 46-character value is rejected (with the error message checked in the shell test and ValueError in Python).

Testing:

  • NO_INTERNET=1 make -C src and make -C src pymod pass, including the new tests.
  • The reporter's ASan PoC reports stack-buffer-overflow ... in my_ip on main and runs cleanly with this change.

Reported by Tushar98644.

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().
@sonarqubecloud

Copy link
Copy Markdown

@manugarg
manugarg merged commit 645a4ce into main Nov 10, 2026
28 checks passed
@manugarg
manugarg deleted the fix-setmyip-length branch November 10, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant