Fix null-deref in os_get_host_and_cname_by_name when ai_canonname is NULL#5875
Open
Mauricio0704 wants to merge 1 commit intobloomberg:mainfrom
Open
Fix null-deref in os_get_host_and_cname_by_name when ai_canonname is NULL#5875Mauricio0704 wants to merge 1 commit intobloomberg:mainfrom
Mauricio0704 wants to merge 1 commit intobloomberg:mainfrom
Conversation
…NULL Signed-off-by: Mauricio0704 <mausancarr0704@gmail.com>
fe6f3ee to
39e97b8
Compare
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.
Type of change
Bug fix.
Current behavior
os_get_host_and_cname_by_name()inutil/bb_oscompat.cdoes*cname = strdup(res->ai_canonname)unconditionally. Per POSIX,getaddrinfowithAI_CANONNAMEmay leaveai_canonname == NULL; macOS does this for bare IPv4 hostnames. Result:strdup(NULL)→ SIGSEGV ingetmyid()before the server logs anything. Linux is unaffected because glibc populatesai_canonnamewith the input literal.Expected behavior
Tolerate
ai_canonname == NULL. The only real caller (getmyidatdb/comdb2.c) already handlescname == NULLby falling back togbl_myhostname, so NULL is a legal return per the caller contract.Steps to reproduce
On macOS with the system hostname set to a bare IP:
comdb2 --create --dir ~/db testdb→ SIGSEGV.After the patch it creates the DB and
comdb2 --lrl ...reachesI AM READY.