Skip to content

fix: check *ret instead of ret in xvasprintf error path - #96

Open
kugland wants to merge 1 commit into
emikulic:masterfrom
kugland:fix/xvasprintf-error-path
Open

fix: check *ret instead of ret in xvasprintf error path#96
kugland wants to merge 1 commit into
emikulic:masterfrom
kugland:fix/xvasprintf-error-path

Conversation

@kugland

@kugland kugland commented May 13, 2026

Copy link
Copy Markdown
Contributor

ret is the address of a local char* and is never NULL, so the OOM branch was dead. Test len == -1 first to short-circuit, since per vasprintf(3) the contents of *strp are undefined on error on GNU; the *ret == NULL check then covers the FreeBSD case, where the implementation sets strp to NULL on error.

ret is the address of a local char* and is never NULL, so the OOM
branch was dead. Test len == -1 first to short-circuit, since per
vasprintf(3) the contents of *strp are undefined on error on GNU;
the *ret == NULL check then covers the FreeBSD case, where the
implementation sets strp to NULL on error.
Comment thread darkhttpd.c
static unsigned int xvasprintf(char **ret, const char *format, va_list ap) {
int len = vasprintf(ret, format, ap);
if (ret == NULL || len == -1)
if (len == -1 || *ret == NULL)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can this condition be simplified to just len == -1?

man 3 printf on FreeBSD says vasprintf() will return -1

@emikulic

Copy link
Copy Markdown
Owner

Sorry for delay. Nice catch.

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.

2 participants