<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-01-18 14:41 GMT+01:00 Ludovic Rousseau <span dir="ltr"><<a href="mailto:ludovic.rousseau@gmail.com" target="_blank">ludovic.rousseau@gmail.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"><div dir="ltr">Hello,<br><div><div class="gmail_extra"><span class="gmail-"><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-m_-7028788469153896710gmail-">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></span><div class="gmail_quote">A really simple fix is:<br>--- /var/folders/jb/<wbr>2mvc64nx74b76qjg_<wbr>5yk8zs00000gn/T//zsNKq9_error.<wbr>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" target="_blank">https://en.wikipedia.org/wiki/<wbr>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></div></div></div></blockquote><div><br></div><div>Fixed in <a href="https://github.com/LudovicRousseau/PCSC/commit/eab1d67295e4e1d5c12bbca77bc57c50fd384a4e">https://github.com/LudovicRousseau/PCSC/commit/eab1d67295e4e1d5c12bbca77bc57c50fd384a4e</a><br></div><div><br>Then the fix was fixed in <a href="https://github.com/LudovicRousseau/PCSC/commit/9726152f2c6767f0fa3103ad307dc28ef7923852">https://github.com/LudovicRousseau/PCSC/commit/9726152f2c6767f0fa3103ad307dc28ef7923852</a><br>Clang accepts "__thread static" but GCC does not and only accepts "static __thread".<br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><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></div></blockquote><div><br></div><div>Applied in <a href="https://github.com/LudovicRousseau/PCSC/commit/b27f0e54194dcfb4db8179dceede8a649141fea4">https://github.com/LudovicRousseau/PCSC/commit/b27f0e54194dcfb4db8179dceede8a649141fea4</a><br><br></div><div>Thansk to all the participants in this thread.<br><br></div><div>Bye<br><br></div></div>-- <br><div class="gmail_signature"> Dr. Ludovic Rousseau</div>
</div></div>