Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260828163902.6754-2-ismael@iodev.co.uk>
Date: Fri, 28 Aug 2026 18:38:55 +0200
From: Ismael Luceno <ismael@...ev.co.uk>
To: musl@...ts.openwall.com
Cc: Rich Felker <dalias@...c.org>,
	Ismael Luceno <ismael@...ev.co.uk>
Subject: [PATCH] catgets: Handle invalid catalog descriptor

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;

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.