<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-02-17 20:34 GMT+01:00 Maximilian Stein <span dir="ltr"><<a href="mailto:maximilian.stein@secunet.com" target="_blank">maximilian.stein@secunet.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">Hello again,<br></blockquote><div><br></div><div>Hello,<br> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
one thing I've noticed while analysing the SCardControl() code is, that<br>
the libccid IFD handler might silently truncate the reader response, if<br>
the RxBuffer is not large enough. In fact it is the CmdEscape() function<br>
that does this. But it is used, amongst others, by IFDHControl() in some<br>
cases (see commands.c:1008):<br>
<br>
    /* copy the response */<br>
    length_out = dw2i(cmd_out, 1);<br>
    if (length_out > *RxLength)<br>
        length_out = *RxLength;<br>
    *RxLength = length_out;<br>
    memcpy(RxBuffer, &cmd_out[10], length_out);<br>
<br>
While other control calls for the reader (e.g. PIN handling) in<br>
IFDHControl() are handled via CCID_Transmit/CCID_Receive which does<br>
(commands.c:1567):<br>
<br>
    length = dw2i(cmd, 1);<br>
    if (length <= *rx_length)<br>
            *rx_length = length;<br>
    else<br>
    {<br>
            DEBUG_CRITICAL2("overrun by %d bytes", length - *rx_length);<br>
            length = *rx_length;<br>
            return_value = IFD_ERROR_INSUFFICIENT_BUFFER;<br>
    }<br>
[...]<br>
        memcpy(rx_buffer, cmd+10, length);<br>
<br>
Is this intended? If so, the behaviour of IFDHControl() is inconsistent<br>
regarding the handling of too small return buffers depending on which<br>
control code is used. Another question is, if it is intended that the<br>
truncated response is delivered to the client together with the<br>
INSUFFICIENT_BUFFER error. The code in CCID_Receive looks a bit like it...<br></blockquote><div><br></div><div>You are right.<br></div><div>Now <span class="gmail-blob-code-inner">IFD_ERROR_INSUFFICIENT_BUFFER is returned. The truncation is no more silent.<br><br></span></div><div><span class="gmail-blob-code-inner">Fixed in <a href="https://github.com/LudovicRousseau/CCID/commit/b15c8f96ca80005c3da024c031e9607051a9fe1a">https://github.com/LudovicRousseau/CCID/commit/b15c8f96ca80005c3da024c031e9607051a9fe1a</a><br><br></span></div><div><span class="gmail-blob-code-inner">Thanks<br></span></div><div><br></div></div>-- <br><div class="gmail_signature"> Dr. Ludovic Rousseau</div>
</div></div>