Skip to content

ext/gettext: avoid NULL deref in textdomain/bindtextdomain - #21882

Merged
iliaal merged 1 commit into
php:masterfrom
iliaal:gettext-null-deref-hardening-8.4
Sep 19, 2026
Merged

iliaal merged 1 commit into
php:masterfrom
iliaal:gettext-null-deref-hardening-8.4

Conversation

@iliaal

@iliaal iliaal commented Apr 27, 2026

Copy link
Copy Markdown
Member

Both textdomain() and bindtextdomain($domain, $dir) can return NULL on libintl-internal allocation failure. RETURN_STRING then calls strlen(NULL) and crashes. Throw an Error in that case instead. Return signatures stay as string so static analyzers don't pick up new false branches.

@iluuu1994

iluuu1994 commented Apr 27, 2026

Copy link
Copy Markdown
Member

I'm not sure adding false for a theoretical error makes sense today. Exceptions would be more fitting. 0221cee was different in that it didn't change the signature of bindtextdomain(), but this will lead to new errors in static analysis tools.

@iliaal

iliaal commented Apr 27, 2026

Copy link
Copy Markdown
Member Author

Let me re-do as exception, since it is basically theoretical (i reproduced via fake lib via LD_PRELOAD) has a plus of not changing return type.

@iliaal
iliaal force-pushed the gettext-null-deref-hardening-8.4 branch from b7039f2 to ee25047 Compare April 27, 2026 12:26

@iluuu1994 iluuu1994 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but maybe target master.

Both functions can return NULL on libintl-internal allocation failure,
which RETURN_STRING then fed to strlen(NULL) and crashed. Throw an
Error in that case instead, leaving the existing string return type
intact (no static-analysis fallout from a widened signature).

The dir==NULL query path of bindtextdomain keeps its RETURN_FALSE
because musl returns NULL there to signal an unbound domain, which is
not an error condition.
@iliaal
iliaal changed the base branch from PHP-8.4 to master September 19, 2026 22:23
@iliaal
iliaal force-pushed the gettext-null-deref-hardening-8.4 branch from ee25047 to 8f0f1b8 Compare September 19, 2026 22:23
@iliaal
iliaal merged commit 894f215 into php:master Sep 19, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants