[svn] GnuPG - r4109 - branches/GNUPG-1-9-BRANCH/scd

svn author marcus cvs at cvs.gnupg.org
Fri Apr 14 22:40:00 CEST 2006


Author: marcus
Date: 2006-04-14 22:40:00 +0200 (Fri, 14 Apr 2006)
New Revision: 4109

Modified:
   branches/GNUPG-1-9-BRANCH/scd/ChangeLog
   branches/GNUPG-1-9-BRANCH/scd/app.c
Log:
2006-04-14  Marcus Brinkmann  <marcus at g10code.de>

	* app.c (select_application): Cover up a slot mismatch error in
	case it happens (it shouldn't happen).
	(release_application): Use APP->slot.  Lock the reader.
	(application_notify_card_removed): Lock the reader.


Modified: branches/GNUPG-1-9-BRANCH/scd/ChangeLog
===================================================================
--- branches/GNUPG-1-9-BRANCH/scd/ChangeLog	2006-04-12 10:36:23 UTC (rev 4108)
+++ branches/GNUPG-1-9-BRANCH/scd/ChangeLog	2006-04-14 20:40:00 UTC (rev 4109)
@@ -1,3 +1,10 @@
+2006-04-14  Marcus Brinkmann  <marcus at g10code.de>
+
+	* app.c (select_application): Cover up a slot mismatch error in
+	case it happens (it shouldn't happen).
+	(release_application): Use APP->slot.  Lock the reader.
+	(application_notify_card_removed): Lock the reader.
+
 2006-04-11  Werner Koch  <wk at g10code.com>
 
 	* command.c (hex_to_buffer): New.

Modified: branches/GNUPG-1-9-BRANCH/scd/app.c
===================================================================
--- branches/GNUPG-1-9-BRANCH/scd/app.c	2006-04-12 10:36:23 UTC (rev 4108)
+++ branches/GNUPG-1-9-BRANCH/scd/app.c	2006-04-14 20:40:00 UTC (rev 4109)
@@ -161,22 +161,25 @@
 void
 application_notify_card_removed (int slot)
 {
+  app_t app;
+
   if (slot < 0 || slot >= DIM (lock_table))
     return;
 
+  /* FIXME: We are ignoring any error value here.  */
+  lock_reader (slot); 
+
   /* Deallocate a saved application for that slot, so that we won't
      try to reuse it.  If there is no saved application, set a flag so
      that we won't save the current state. */
-  if (lock_table[slot].initialized)
+  app = lock_table[slot].last_app;
+
+  if (app)
     {
-      app_t app = lock_table[slot].last_app;
-
-      if (app)
-        {
-          lock_table[slot].last_app = NULL;
-          deallocate_app (app);
-        }
+      lock_table[slot].last_app = NULL;
+      deallocate_app (app);
     }
+  unlock_reader (slot); 
 }
 
  
@@ -262,6 +265,8 @@
     {
       if (app->slot != slot)
         log_bug ("slot mismatch %d/%d\n", app->slot, slot);
+      app->slot = slot;
+
       app->ref_count++;
       *r_app = app;
       unlock_reader (slot);
@@ -400,18 +405,22 @@
     return;
 
   /* Move the reference to the application in the lock table. */
-  for (slot = 0;  slot < DIM (lock_table); slot++)
-    if (lock_table[slot].initialized && lock_table[slot].app == app)
-      {
-        if (lock_table[slot].last_app)
-          deallocate_app (lock_table[slot].last_app);
-        lock_table[slot].last_app = lock_table[slot].app;
-        lock_table[slot].app = NULL;
-        return;
-      }
+  slot = app->slot;
+  /* FIXME: We are ignoring any error value.  */
+  lock_reader (slot);
+  if (lock_table[slot].app != app)
+    {
+      unlock_reader (slot);
+      log_bug ("app mismatch %p/%p\n", app, lock_table[slot].app);
+      deallocate_app (app);
+      return;
+    }
 
-  log_debug ("application missing in lock table - deallocating anyway\n");
-  deallocate_app (app);
+  if (lock_table[slot].last_app)
+    deallocate_app (lock_table[slot].last_app);
+  lock_table[slot].last_app = lock_table[slot].app;
+  lock_table[slot].app = NULL;
+  unlock_reader (slot);
 }
 
 




More information about the Gnupg-commits mailing list