<div dir="ltr">If the current locale settings on a system are somehow broken, the<br>newlocale function can fail and return a null locale object. According<br>to the documentation, subsequent calls to strerror_l and freelocale have<br>
an undefined behavior. This may be a segmentation fault.<br><br>When newlocale fails, return NULL, and cover this case in vlc_strerror,<br>where vlc_error_c can be used as a backup.<br>---<br> src/posix/error.c | 10 +++++++++-<br>
1 file changed, 9 insertions(+), 1 deletion(-)<br><br>diff --git a/src/posix/error.c b/src/posix/error.c<br>index acb42c9..b270e6e 100644<br>--- a/src/posix/error.c<br>+++ b/src/posix/error.c<br>@@ -30,6 +30,9 @@<br> static const char *vlc_strerror_l(int errnum, const char *lname)<br>
{<br> locale_t loc = newlocale(LC_MESSAGES_MASK, lname, (locale_t)0);<br>+ if (!loc)<br>+ return NULL;<br>+<br> const char *buf = strerror_l(errnum, loc);<br> <br> freelocale(loc);<br>@@ -38,6 +41,8 @@ static const char *vlc_strerror_l(int errnum, const char *lname)<br>
<br> /**<br> * Formats an error message in the current locale.<br>+ * If there is an issue with the current locale, then @ref vlc_strerror_c<br>+ * is used instead.<br> * @param errnum error number (as in errno.h)<br> * @return A string pointer, valid until the next call to a function of the<br>
* strerror() family in the same thread. This function cannot fail.<br>@@ -45,7 +50,10 @@ static const char *vlc_strerror_l(int errnum, const char *lname)<br> const char *vlc_strerror(int errnum)<br> {<br> /* We cannot simply use strerror() here, since it is not thread-safe. */<br>
- return vlc_strerror_l(errnum, "");<br>+ const char *buf = vlc_strerror_l(errnum, "");<br>+ if (!buf)<br>+ return vlc_strerror_c(errnum);<br>+ return buf;<br> }<br> <br> /**<br>-- <br>
2.0.0<br></div>