Repository navigation
libs/libc/netdb: separate h_errno from EAI error codes - #20693
Merged
xiaoxiang781216 merged 1 commit intoOct 26, 2026
Merged
Conversation
Swatantra-66
requested review from
Donny9,
antmerlino,
xiaoxiang781216 and
yamt
as code owners
October 15, 2026 19:36
Swatantra-66
force-pushed
the
fix/libc-netdb-herrno
branch
from
October 15, 2026 20:39
ed9ef52 to
30deaa2
Compare
|
xiaoxiang781216
approved these changes
Oct 16, 2026
xiaoxiang781216
approved these changes
Oct 17, 2026
gethostentbyname_r() previously set *h_errnop to EAI_NONAME when AI_NUMERICHOST was specified and the hostname was non-numeric. Because *h_errnop is an h_errno output parameter used by gethostbyname_r() and gethostbyname2_r(), setting EAI_NONAME (6) corrupted h_errno with an invalid value. Additionally, getaddrinfo() passed &ret as the h_errnop argument to gethostentbyname_r(), ignored gethostentbyname_r()'s actual return status (OK/ERROR), and returned ret directly. As a result, getaddrinfo() returned raw h_errno values (e.g., HOST_NOT_FOUND = 1, TRY_AGAIN = 4) instead of standard POSIX EAI_xxx error codes (EAI_NONAME = 6, EAI_AGAIN = 2). This patch: 1. Sets *h_errnop to HOST_NOT_FOUND (or TRY_AGAIN on transient DNS timeouts/errors) in gethostentbyname_r(). 2. Passes a dedicated &herrno variable from getaddrinfo() to gethostentbyname_r() and checks the function return value. 3. Explicitly maps h_errno codes to POSIX EAI_xxx codes (HOST_NOT_FOUND and NO_DATA -> EAI_NONAME, TRY_AGAIN -> EAI_AGAIN, NO_RECOVERY -> EAI_FAIL). Fixes apache#15752 Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/libc-netdb-herrno
branch
from
October 21, 2026 18:50
30deaa2 to
a2ea564
Compare
casaroli
approved these changes
Oct 25, 2026
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.
Summary
Resolves #15752.
gethostentbyname_r()previously set*h_errnoptoEAI_NONAMEwhenAI_NUMERICHOSTwas specified and the hostname was non-numeric. Because*h_errnopis anh_errnooutput parameter used bygethostbyname_r()andgethostbyname2_r(), settingEAI_NONAME(6) corruptedh_errnowith an invalid value.Additionally,
getaddrinfo()passed&retas theh_errnopargument togethostentbyname_r(), ignoredgethostentbyname_r()'s actual return status (OK/ERROR), and returnedretdirectly. As a result,getaddrinfo()returned rawh_errnovalues (e.g.,HOST_NOT_FOUND= 1,TRY_AGAIN= 4) instead of standard POSIXEAI_xxxerror codes (EAI_NONAME= 6,EAI_AGAIN= 2).This patch:
*h_errnoptoHOST_NOT_FOUND(orTRY_AGAINon transient DNS timeouts/errors) ingethostentbyname_r().&herrnovariable fromgetaddrinfo()togethostentbyname_r()and checks the function return value.h_errnocodes to POSIXEAI_xxxcodes:HOST_NOT_FOUNDandNO_DATA->EAI_NONAMETRY_AGAIN->EAI_AGAINNO_RECOVERY->EAI_FAILImpact
h_errnoreporting ingethostbyname_r(),gethostbyname2_r(),gethostbyname(), andgethostbyname2().EAI_xxxreturn codes ingetaddrinfo().Testing
tools/checkpatch.sh(0 errors, 0 warnings).