aboutsummaryrefslogtreecommitdiff
path: root/string/strerror_l.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2023-06-15 12:08:22 +0200
committerFlorian Weimer <fweimer@redhat.com>2023-06-15 19:54:09 +0200
commit1d44530a5be2442e064baa48139adc9fdfb1fc6b (patch)
tree99321e32c7e27993de27c359e2022afe1fdf8c91 /string/strerror_l.c
parent388ae538ddcb05c7d8966147b488a5f6e481656e (diff)
downloadglibc-1d44530a5be2442e064baa48139adc9fdfb1fc6b.tar.xz
glibc-1d44530a5be2442e064baa48139adc9fdfb1fc6b.zip
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. Reviewed-by: Arjun Shankar <arjun@redhat.com>
Diffstat (limited to 'string/strerror_l.c')
-rw-r--r--string/strerror_l.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/string/strerror_l.c b/string/strerror_l.c
index 7fe9b1d903..e5c8666198 100644
--- a/string/strerror_l.c
+++ b/string/strerror_l.c
@@ -43,10 +43,15 @@ __strerror_l (int errnum, locale_t loc)
struct tls_internal_t *tls_internal = __glibc_tls_internal ();
free (tls_internal->strerror_l_buf);
if (__asprintf (&tls_internal->strerror_l_buf, "%s%d",
- translate ("Unknown error ", loc), errnum) == -1)
- tls_internal->strerror_l_buf = NULL;
-
- err = tls_internal->strerror_l_buf;
+ translate ("Unknown error ", loc), 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 (err, loc);