about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2024-11-09 19:54:08 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2024-11-09 20:00:40 +0100
commitd2e65aa7d6a6434672abcaecd61877bfa78eeb1d (patch)
treec840374e9ded5558bd91dd84eeeff2a860fb72f3
parent6754b5becf403a3c6b95a0ebd829edf8e4d83251 (diff)
downloadglibc-d2e65aa7d6a6434672abcaecd61877bfa78eeb1d.tar.gz
glibc-d2e65aa7d6a6434672abcaecd61877bfa78eeb1d.tar.xz
glibc-d2e65aa7d6a6434672abcaecd61877bfa78eeb1d.zip
mach: Fix __xpg_strerror_r on in-range but undefined errors [BZ #32350]
For instance, 1073741906 leads to system 16, subsystem 0 and code 82,
which is in range (max_code is 122), but not defined. Return EINVAL in
that case, like
-rw-r--r--sysdeps/mach/xpg-strerror.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sysdeps/mach/xpg-strerror.c b/sysdeps/mach/xpg-strerror.c
index f8c65f8124..5e0e5a41d7 100644
--- a/sysdeps/mach/xpg-strerror.c
+++ b/sysdeps/mach/xpg-strerror.c
@@ -62,9 +62,19 @@ __xpg_strerror_r (int errnum, char *buf, size_t buflen)
   if (sub >= es->max_sub)
     estr = (const char *) es->bad_sub;
   else if (code >= es->subsystem[sub].max_code)
-    return EINVAL;
+    {
+      __snprintf (buf, buflen, "%s%d", _("Unknown error code: "), code);
+      return EINVAL;
+    }
   else
-    estr = (const char *) _(es->subsystem[sub].codes[code]);
+    {
+      estr = (const char *) _(es->subsystem[sub].codes[code]);
+      if (estr == NULL)
+	{
+	  __snprintf (buf, buflen, "%s%d", _("Unknown error code: "), code);
+	  return EINVAL;
+	}
+    }
 
   size_t estrlen = strlen (estr);