[svn] GnuPG - r4555 - trunk/scd

svn author wk cvs at cvs.gnupg.org
Wed Aug 1 20:26:02 CEST 2007


Author: wk
Date: 2007-08-01 20:25:32 +0200 (Wed, 01 Aug 2007)
New Revision: 4555

Modified:
   trunk/scd/ChangeLog
   trunk/scd/apdu.c
Log:
Applied exact length hack.


Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2007-08-01 18:13:31 UTC (rev 4554)
+++ trunk/scd/ChangeLog	2007-08-01 18:25:32 UTC (rev 4555)
@@ -1,3 +1,8 @@
+2007-08-01  Werner Koch  <wk at g10code.com>
+
+	* apdu.c (send_le): Implement exact length hack.  Suggested by
+	Sten Lindgren.
+
 2007-07-05  Werner Koch  <wk at g10code.com>
 
 	* command.c (has_option_name, skip_options): New.

Modified: trunk/scd/apdu.c
===================================================================
--- trunk/scd/apdu.c	2007-08-01 18:13:31 UTC (rev 4554)
+++ trunk/scd/apdu.c	2007-08-01 18:25:32 UTC (rev 4555)
@@ -2609,7 +2609,8 @@
   unsigned char apdu[5+256+1];
   size_t apdulen;
   int sw;
-  long rc; /* we need a long here due to PC/SC. */
+  long rc; /* We need a long here due to PC/SC. */
+  int did_exact_length_hack = 0;
 
   if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
     return SW_HOST_NO_DRIVER;
@@ -2648,6 +2649,7 @@
   assert (sizeof (apdu) >= apdulen);
   /* As safeguard don't pass any garbage from the stack to the driver. */
   memset (apdu+apdulen, 0, sizeof (apdu) - apdulen);
+ exact_length_hack:
   resultlen = RESULTLEN;
   rc = send_apdu (slot, apdu, apdulen, result, &resultlen, pininfo);
   if (rc || resultlen < 2)
@@ -2658,7 +2660,14 @@
       return rc? rc : SW_HOST_INCOMPLETE_CARD_RESPONSE;
     }
   sw = (result[resultlen-2] << 8) | result[resultlen-1];
-  /* store away the returned data but strip the statusword. */
+  if (!did_exact_length_hack && SW_EXACT_LENGTH_P (sw))
+    {
+      apdu[apdulen-1] = (sw & 0x00ff);
+      did_exact_length_hack = 1;
+      goto exact_length_hack;
+    }
+
+  /* Store away the returned data but strip the statusword. */
   resultlen -= 2;
   if (DBG_CARD_IO)
     {




More information about the Gnupg-commits mailing list