<div dir="ltr">Your observations are correct, and I have tried to come up with a better version of the patch. But probably there are still issues which I am unable to detect because of my lack of experience.<br>--<br><br>If the newlocale function fails and returns (locale_t)0,  subsequent calls to<br>
strerror_l and freelocale have an undefined behavior. In this case, construct<br>a special error message in a separate buffer, indicating that there was a<br>problem with the locale name and getting the error message using strerror_r.<br>
---<br> src/posix/error.c | 29 +++++++++++++++++++++++++++++<br> 1 file changed, 29 insertions(+)<br><br>diff --git a/src/posix/error.c b/src/posix/error.c<br>index acb42c9..998cd34 100644<br>--- a/src/posix/error.c<br>+++ b/src/posix/error.c<br>
@@ -30,6 +30,35 @@<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>+<br>+    // Special handling in case of newlocale function failure<br>
+    if (!loc)<br>+    {<br>+#define ERR_MSG_SIZE 0x40<br>+        static char err_msg_buf[ERR_MSG_SIZE];<br>+        static char special_err_msg[ERR_MSG_SIZE];<br>+        char *err_msg;<br>+<br>+#if (_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE<br>
+        // XSI-compliant variant of strerror_r<br>+        strerror_r(errnum, err_msg_buf, ERR_MSG_SIZE);<br>+        err_msg = err_msg_buf;<br>+#else<br>+        // GNU-specific variant of strerror_r<br>+        err_msg = strerror_r(errnum, err_msg_buf, ERR_MSG_SIZE);<br>
+#endif<br>+<br>+        if (strlen(lname))<br>+            snprintf(special_err_msg, ERR_MSG_SIZE,<br>+                    "[bad locale %s for error msg] %s", lname, err_msg);<br>+        else<br>+            snprintf(special_err_msg, ERR_MSG_SIZE,<br>
+                    "[bad default locale for error msg] %s", err_msg);<br>+<br>+        return special_err_msg;<br>+#undef ERR_MSG_SIZE<br>+    }<br>+<br>     const char *buf = strerror_l(errnum, loc);<br> <br>
     freelocale(loc);<br>-- <br>2.0.0<br><br><div class="gmail_extra"><br><br><div class="gmail_quote">2014-07-07 12:24 GMT+03:00 Rémi Denis-Courmont <span dir="ltr"><<a href="mailto:remi@remlab.net" target="_blank">remi@remlab.net</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le 2014-07-07 12:05, Casian Andrei a écrit :<div class=""><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If the current locale settings on a system are somehow broken, the<br>
newlocale function can fail and return a null locale object.<br>
</blockquote>
<br></div>
Sorry but that is too fuzzy a problem description in my opinion.<div class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
According to the documentation, subsequent calls to strerror_l<br>
and freelocale have an undefined behavior.<br>
</blockquote>
<br></div>
True but (vlc_)strerror_l() cannot return NULL ever anyway. So the patch is buggy.<div class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
When newlocale fails, return NULL, and cover this case in<br>
vlc_strerror, where vlc_error_c can be used as a backup.<br>
</blockquote>
<br></div>
I find addressing a failure of newlocale() with another call to newlocale() dubious.<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Rémi Denis-Courmont<br>
______________________________<u></u>_________________<br>
vlc-devel mailing list<br>
To unsubscribe or modify your subscription options:<br>
<a href="https://mailman.videolan.org/listinfo/vlc-devel" target="_blank">https://mailman.videolan.org/<u></u>listinfo/vlc-devel</a><br>
</font></span></blockquote></div><br></div></div>