Bug in verbose flag handling in cardos-tool.c

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Bug in verbose flag handling in cardos-tool.c

Etienne Cordonnier
Hi!
The way the verbose flag is handled in src/tools/cardos-tool.c is not correct, see for instance:

 335     if (apdu.sw1 != 0x90 || apdu.sw2 != 00 || verbose) {                    
 336         fprintf(stderr, "Received (SW1=0x%02X, SW2=0x%02X)%s\n",                
 337             apdu.sw1, apdu.sw2, apdu.resplen ? ":" : "");                      
 338         if (apdu.resplen)                                                      
 339             util_hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);            
 340         return 1;                                                              
 341     }

When running cardos-tool with -v, the program returns 1 as soon as it reaches one of those blocks, because the condition “|| verbose” is true.
Should I send a pull request extracting those checks in a function and correcting the behaviour? I think the wanted behaviour is the following:

      if (apdu.sw1 != 0x90 || apdu.sw2 != 00 || verbose) {                    
          fprintf(stderr, "Received (SW1=0x%02X, SW2=0x%02X)%s\n",                
              apdu.sw1, apdu.sw2, apdu.resplen ? ":" : "");                      
          if (apdu.resplen)                                                      
              util_hex_dump_asc(stdout, apdu.resp, apdu.resplen, -1);  
          if (apdu.sw1 != 0x90 || apdu.sw2 != 00)          
             return 1;                                                              
      }

Cordially,
Etienne
------------------------------------------------------------------------------
_______________________________________________
Opensc-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opensc-devel