<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2017-02-18 19:06 GMT+01:00 Wolfgang Pichler <span dir="ltr"><<a href="mailto:wpichler@callino.at" target="_blank">wpichler@callino.at</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">Hi all,<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>
struggling with my gemalto stick (as in my previous mail) - i found a possible bug - for which i now created a workaround - because i don’t know the exact source for the problem.<br>
<br>
In libccid-1.4.22<br>
<br>
in src/ccid_usb.c - in the ReadUSB Function<br>
<br>
For whatever Reason - it got called for my stick with a value of 65556 (the main thing here will be to find out why it does like to read that many bytes…)<br>
<br>
The call to libusb_bulk_transfer did failed then - but did not return something negative - only 0 bytes.<br>
<br>
libusb_bulk_transfer is defined with the length as int (not unsigend int !) - for whatever reason<br></blockquote><div><br></div><div>This change is planed for a next major version of libusb: use size_t instead of int for a buffer size.<br></div><div><br>Note that 65556 can easily be stored in a 4-bytes int.<br><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">
so the unsigned int value will get a negative value - so the libusb_bulk_transfer will return with 0 bytes because it can not read negative number of bytes (this sound clear to me)<br></blockquote><div><br></div><div>Your int is a 2-bytes value?<br>What platform are you using?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
So - quick and dirty - i added a check if the value is greater than 4096 - then make the length=4096 - and do read<br>
<br>
--- ccid-1.4.22/src/ccid_usb.c  2016-01-10 13:26:09.000000000 +0000<br>
+++ ccid-1.4.22-patched/src/ccid_<wbr>usb.c  2017-02-18 18:02:40.225678226 +0000<br>
@@ -800,7 +800,9 @@<br>
 read_again:<br>
        (void)snprintf(debug_header, sizeof(debug_header), "<- %06X ",<br>
                (int)reader_index);<br>
-<br>
+       if (*length > 4096) {<br>
+               *length = 4096;<br>
+       }<br>
        rv = libusb_bulk_transfer(<wbr>usbDevice[reader_index].dev_<wbr>handle,<br>
                usbDevice[reader_index].bulk_<wbr>in, buffer, *length,<br>
                &actual_length, usbDevice[reader_index].ccid.<wbr>readTimeout);<br>
<br>
<br>
At the start it does throw this failure<br>
<br>
00000020 ccid.c:212:set_gemalto_<wbr>firmware_features() GET_FIRMWARE_FEATURES failed: 612, len=0<br>
<br>
Maybe because of this it does not know the max size which it could read from the device ?<br></blockquote><div><br></div><div>Can you provide a full pcscd log (without any code change)?<br><br></div><div>Thanks<br clear="all"></div></div><br>-- <br><div class="gmail_signature"> Dr. Ludovic Rousseau</div>
</div></div>