Skip to content

Check for NULL ai_canonname in ospect::os::unix::fqdn. - #239

Open
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-ospect-unix-fqdn-null
Open

Check for NULL ai_canonname in ospect::os::unix::fqdn.#239
grrrrrrrrr wants to merge 1 commit into
google:masterfrom
grrrrrrrrr:fix-ospect-unix-fqdn-null

Conversation

@grrrrrrrrr

Copy link
Copy Markdown
Collaborator

In ospect::os::unix::fqdn, getaddrinfo is invoked with the
AI_CANONNAME flag. POSIX allows getaddrinfo to return 0 (success)
while leaving ai_canonname as NULL if canonical name lookup fails or
only numeric addresses are resolved. Calling CStr::from_ptr on a NULL
pointer resulted in an immediate segmentation fault.

This change verifies that ai_canonname is non-NULL before constructing
the CStr and ensures freeaddrinfo is always called before returning.

In `ospect::os::unix::fqdn`, `getaddrinfo` is invoked with the
`AI_CANONNAME` flag. POSIX allows `getaddrinfo` to return 0 (success)
while leaving `ai_canonname` as NULL if canonical name lookup fails or
only numeric addresses are resolved. Calling `CStr::from_ptr` on a NULL
pointer resulted in an immediate segmentation fault.

This change verifies that `ai_canonname` is non-NULL before constructing
the `CStr` and ensures `freeaddrinfo` is always called before returning.
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