Skip to content

Conversation

ckhardin
Copy link
Contributor

@ckhardin ckhardin commented Oct 3, 2025

Deal with some issues found during a misconfiguration of the DNS resolver that ended up leading into a problem in the base inet_ntop implementation not checking the bounds of the passed in buffer and overwriting the passed in dst.

@ckhardin ckhardin force-pushed the ckhardin/fix-inet-ntop-buffer-size branch from caf7d87 to 7d0c800 Compare October 3, 2025 00:56
From the manpage for inet_ntop

  This function converts the network address structure src in the af
  address family into a character string.  The resulting string is
  copied to the buffer pointed to by dst, which must be a non-null
  pointer.  The caller specifies the number of bytes available in
  this buffer in the argument size.

In an unintended misconfiguration the resolve max string ended up
being 20 and tracking thru some wierd code issues determined some
stack corruption which came back to the shell command. So, just
fix the size argument to be the sizeof which then leads to the next
problem that the size is being ignored by inet_ntop.

Signed-off-by: Charles Hardin <[email protected]>
@ckhardin ckhardin force-pushed the ckhardin/fix-inet-ntop-buffer-size branch from 7d0c800 to b33041e Compare October 3, 2025 01:11
@ckhardin ckhardin force-pushed the ckhardin/fix-inet-ntop-buffer-size branch 4 times, most recently from 8361ffe to 0a43f16 Compare October 5, 2025 00:28
@zephyrbot zephyrbot requested a review from rerickson1 October 5, 2025 00:30
@ckhardin ckhardin force-pushed the ckhardin/fix-inet-ntop-buffer-size branch 2 times, most recently from dbef1ae to ad4fbc7 Compare October 5, 2025 01:33
The code was writing to the dst without a verification check on
size which is not appropriate. The guard on the arguements should
be enforced and so just ensure the size is larger then the
definition of the strings from POSIX and return an error in those
cases.

Signed-off-by: Charles Hardin <[email protected]>
@ckhardin ckhardin force-pushed the ckhardin/fix-inet-ntop-buffer-size branch from ad4fbc7 to 25bab1c Compare October 5, 2025 02:01
Copy link

sonarqubecloud bot commented Oct 5, 2025

Copy link
Member

@jukkar jukkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this is good so we avoid increasing stack usage too much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants