<div dir="ltr">Hello,<br><div><div class="gmail_extra"><br><div class="gmail_quote">2017-01-18 11:29 GMT+01:00 Nikos Mavrogiannopoulos <span dir="ltr"><<a href="mailto:nmav@redhat.com" target="_blank">nmav@redhat.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Tue, 2017-01-17 at 20:33 +0100, Maksim Ivanov wrote:<br>
<br>
> The pcsc_stringify_error function in the PC/SC-Lite implementation<br>
> uses a statically allocated buffer. This means that the buffer may be<br>
> used simultaneously when the function is called from multiple threads<br>
> concurrently.<br>
> Therefore, the returned message may be spoiled, e.g.:<br>
> "Internal error.ul"<br>
> or<br>
> "Command cancell"<br>
> In the worst-case scenario, the application may read an unbounded<br>
> string (with the terminating null character missing).<br>
<br>
</span>A possible fix is attached. That avoids copying strings which are <br>
constant on global store, and ensures that the static buffer is on<br>
thread local store when possible.<br>
<br>
Except compilation, the fix is completely untested.<br></blockquote><br></div><div class="gmail_quote">A really simple fix is:<br>--- /var/folders/jb/2mvc64nx74b76qjg_5yk8zs00000gn/T//zsNKq9_error.c 2017-01-18 14:37:19.000000000 +0100<br>+++ src/error.c 2017-01-17 22:20:08.000000000 +0100<br>@@ -76,7 +76,7 @@ PCSC_API char* pcsc_stringify_error(cons<br> */<br> PCSC_API char* pcsc_stringify_error(const LONG pcscError)<br> {<br>- static char strError[75];<br>+ __thread static char strError[75];<br> const char *msg = NULL;<br> <br> switch (pcscError)<br><br></div><div class="gmail_quote">I tested it with success.<br></div><br>It looks like __thread is standard and not GNU C specific. So maybe your test to limit its use to GCC is not needed and, in fact, problematic.<br>According to <a href="https://en.wikipedia.org/wiki/Thread-local_storage">https://en.wikipedia.org/wiki/Thread-local_storage</a> it is supported by Solaris Studio C/C++, IBM XL C/C++, GNU C, Clang and Intel C++ Compiler (Linux systems).<br><br></div><div class="gmail_extra">Adding const to the pcsc_stringify_error() protottype is also a good idea. I don't think it would break existing compilation. Any comment on that?<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Bye<br><br></div><div class="gmail_extra">--<br><div class="gmail_signature"> Dr. Ludovic Rousseau</div>
</div></div></div>