Skip to content

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
Mauricio0704:fix-strdup-null-ai-canonname
Open

Fix null-deref in os_get_host_and_cname_by_name when ai_canonname is NULL#5875
Mauricio0704 wants to merge 1 commit intobloomberg:mainfrom
Mauricio0704:fix-strdup-null-ai-canonname

Conversation

@Mauricio0704
Copy link
Copy Markdown

Type of change

Bug fix.

Current behavior

os_get_host_and_cname_by_name() in util/bb_oscompat.c does *cname = strdup(res->ai_canonname) unconditionally. Per POSIX, getaddrinfo with AI_CANONNAME may leave ai_canonname == NULL; macOS does this for bare IPv4 hostnames. Result: strdup(NULL) → SIGSEGV in getmyid() before the server logs anything. Linux is unaffected because glibc populates ai_canonname with the input literal.

Expected behavior

Tolerate ai_canonname == NULL. The only real caller (getmyid at db/comdb2.c) already handles cname == NULL by falling back to gbl_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 ... reaches I AM READY.

…NULL

Signed-off-by: Mauricio0704 <mausancarr0704@gmail.com>
@Mauricio0704 Mauricio0704 force-pushed the fix-strdup-null-ai-canonname branch from fe6f3ee to 39e97b8 Compare April 16, 2026 19:15
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