musl libc's implementation of catgets() crashes when its first argument
is -1 instead of a proper message catalog descriptor. Prevent that from
happening by making isc_msgcat_get() return the default text if the
prior call to catopen() returns an error.
#ifdef HAVE_CATGETS
/*
- * We don't check if catopen() fails because we don't care.
- * If it does fail, then when we call catgets(), it will use
- * the default string.
+ * We don't check if catopen() fails because isc_msgcat_get() takes
+ * care of that before calling catgets().
*/
msgcat->catalog = catopen(name, 0);
#endif
REQUIRE(default_text != NULL);
#ifdef HAVE_CATGETS
- if (msgcat == NULL)
+ if (msgcat == NULL || msgcat->catalog == (nl_catd)(-1)) {
return (default_text);
+ }
return (catgets(msgcat->catalog, set, message, default_text));
#else
return (default_text);