Skip to content

Fix malformed IPv4 address parsing in FreeRTOS_inet_pton4() - #1377

Open
pamirmundt wants to merge 1 commit into
FreeRTOS:mainfrom
pamirmundt:fix/inet-pton4-invalid-input
Open

pamirmundt wants to merge 1 commit into
FreeRTOS:mainfrom
pamirmundt:fix/inet-pton4-invalid-input

Conversation

@pamirmundt

@pamirmundt pamirmundt commented Oct 25, 2026 •

Copy link
Copy Markdown

Description

FreeRTOS_inet_pton4() could accept malformed IPv4 addresses in two cases:

  • Empty octets: Addresses such as 192..1.1 could be accepted because empty octets were interpreted as zero.
  • Integer overflow: Large decimal values could overflow the 32-bit accumulator and wrap into the valid octet range. For example, 4294967296.1.2.3 could be interpreted as 0.1.2.3.

This change rejects empty octets and checks the accumulated value after each digit, preventing integer overflow.

Testing

Added unit tests covering:

  • Empty octets in different positions
  • Out-of-range octets and integer overflow cases
  • Valid IPv4 addresses and boundary values
  • Destination buffer contents on failure

The existing API and valid address handling remain unchanged.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Reject empty octets and out-of-range decimal values before integer overflow can occur.

Add regression tests for invalid inputs, overflow cases, and valid IPv4 address boundaries.
@pamirmundt
pamirmundt force-pushed the fix/inet-pton4-invalid-input branch 2 times, most recently from c868d5f to f37e1cb Compare November 2, 2026 20:06

This branch has not been deployed

No deployments
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