public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Samuel Thibault <sthibaul@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc] mach: strerror must not return NULL (bug 30555)
Date: Sun,  2 Jul 2023 11:30:18 +0000 (GMT)	[thread overview]
Message-ID: <20230702113018.C13053858412@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=efdb85183aca7634d61a413c55d63e519d89d162

commit efdb85183aca7634d61a413c55d63e519d89d162
Author: Samuel Thibault <samuel.thibault@ens-lyon.org>
Date:   Sun Jul 2 11:27:51 2023 +0000

    mach: strerror must not return NULL (bug 30555)
    
    This follows 1d44530a5be2 ("string: strerror must not return NULL (bug 30555)"):
    
    «
        For strerror, this fixes commit 28aff047818eb1726394296d27b ("string:
        Implement strerror in terms of strerror_l").  This commit avoids
        returning NULL for strerror_l as well, although POSIX allows this
        behavior for strerror_l.
    »

Diff:
---
 sysdeps/mach/strerror_l.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c
index 412e38ba52..6555185da7 100644
--- a/sysdeps/mach/strerror_l.c
+++ b/sysdeps/mach/strerror_l.c
@@ -61,11 +61,18 @@ __strerror_l (int errnum, locale_t loc)
       free (tls_internal->strerror_l_buf);
       if (__asprintf (&tls_internal->strerror_l_buf, "%s%X",
 		      translate ("Error in unknown error system: ", loc),
-		      errnum) == -1)
-	tls_internal->strerror_l_buf = NULL;
+		      errnum) > 0)
+	err = tls_internal->strerror_l_buf;
+      else
+	{
+	  /* The memory was freed above.  */
+	  tls_internal->strerror_l_buf = NULL;
+	  /* Provide a fallback translation.  */
+	  err = (char *) translate ("Unknown error", loc);
+	}
 
       __set_errno (saved_errno);
-      return tls_internal->strerror_l_buf;
+      return err;
     }
 
   es = &__mach_error_systems[system];
@@ -79,10 +86,15 @@ __strerror_l (int errnum, locale_t loc)
       if (__asprintf (&tls_internal->strerror_l_buf, "%s%s %d",
 		      translate ("Unknown error ", loc),
 		      translate (es->subsystem[sub].subsys_name, loc),
-		      errnum) == -1)
-	tls_internal->strerror_l_buf = NULL;
-
-      err = tls_internal->strerror_l_buf;
+		      errnum) > 0)
+	err = tls_internal->strerror_l_buf;
+      else
+	{
+	  /* The memory was freed above.  */
+	  tls_internal->strerror_l_buf = NULL;
+	  /* Provide a fallback translation.  */
+	  err = (char *) translate ("Unknown error", loc);
+	}
     }
   else
     err = (char *) translate (es->subsystem[sub].codes[code], loc);

                 reply	other threads:[~2023-07-02 11:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230702113018.C13053858412@sourceware.org \
    --to=sthibaul@sourceware.org \
    --cc=glibc-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).