|
|
Message-ID: <20260828231449.GR23438@brightrain.aerifal.cx>
Date: Fri, 28 Aug 2026 19:14:49 -0400
From: Rich Felker <dalias@...c.org>
To: Ismael Luceno <ismael@...ev.co.uk>
Cc: musl@...ts.openwall.com
Subject: Re: [PATCH] catgets: Handle invalid catalog descriptor
On Fri, Aug 28, 2026 at 06:38:55PM +0200, Ismael Luceno wrote:
> catopen returns -1 on failure, but catgets dereferenced its catd argument
> unconditionally, so passing that value crashed. POSIX allows catgets to
> fail with EBADF for an invalid descriptor and requires it to return the
> caller-supplied default string.
>
> Callers relying on this are common: tcsh calls catopen unconditionally and
> feeds the result to catgets without checking it, so every tcsh invocation
> segfaulted on a system with no message catalogs installed.
>
> Signed-off-by: Ismael Luceno <ismael@...ev.co.uk>
> ---
> src/locale/catgets.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/src/locale/catgets.c b/src/locale/catgets.c
> index 71c31c1d6d01..01a4121551c2 100644
> --- a/src/locale/catgets.c
> +++ b/src/locale/catgets.c
> @@ -15,6 +15,10 @@ static int cmp(const void *a, const void *b)
>
> char *catgets (nl_catd catd, int set_id, int msg_id, const char *s)
> {
> + if (catd == (nl_catd)-1) {
> + errno = EBADF;
> + return (char *)s;
> + }
> const char *map = (const char *)catd;
> uint32_t nsets = V(map+4);
> const char *sets = map+20;
Is this widespread behavior on all existing implementations other than
musl that's just not standardized? Based on your findings about tcsh
that sounds likely.
Generally we don't do "may fail" error conditions for conditions that
are UB, but if this is essentially just a place where the standard
failed to document what all existing implementations do and what
applications expect, it might make sense to do here.
I guess it might be that they didn't want to specify a behavior for
"not a valid message catalog descriptor" since that's not a detectable
condition, despite "is equal to (nl_catd)-1" being a special case of
that which can be detected.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.