Ok, it is probably a good idea to mask both values before comparing. Although, for network addresses one would usually put zeroes in the subnet address, e.g. 192.168.1.0 netmask 255.255.255.0 ...

I tested your patch successfully with one modification: ctx needs to be inserted in the sc_error funtion. - sc_error("length of atr and atr mask do not match - ignored: %s - %s", tatr, matr); + sc_error(ctx,"length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);

Regards,
Heiko


Andreas Jellinghaus schrieb:
or mask both values before comparing?

Index: card.c
===================================================================
--- card.c      (revision 3093)
+++ card.c      (working copy)
@@ -765,14 +765,20 @@
                        matr_len = strlen(matr);
                        if (tatr_len != matr_len)
                                continue;
+                       tbin_len = sizeof(tbin);
+                       sc_hex_to_bin(tatr, tbin, &tbin_len);
                        mbin_len = sizeof(mbin);
                        sc_hex_to_bin(matr, mbin, &mbin_len);
-                       if (mbin_len != card_atr_bin_len)
+                       if (mbin_len != card_atr_bin_len) {
+ sc_error("length of atr and atr mask do not match - ignored: %s - %s", tatr, matr);
                                continue;
+                       }
+                       /* reduce tatr with mask */
+                       for (s = 0; s < tbin_len; s++)
+                               tbin[s] = (tbin[s] & mbin[s]);
+                       /* create copy of card_atr_bin masked) */
                        for (s = 0; s < mbin_len; s++)
                                mbin[s] = (card_atr_bin[s] & mbin[s]);
-                       tbin_len = sizeof(tbin);
-                       sc_hex_to_bin(tatr, tbin, &tbin_len);
                        if (memcmp(tbin, mbin, tbin_len) != 0)
                                continue;
                } else {


might be easier to understand. also adds an error message for the
matr_len != tatr_len case which should not be silently ignored I think,
as a simply typo can trigger it.

what do you think?

Regards, Andreas

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to