Skip to content

Commit

Permalink
ATRDecodeAtr: always initialize the return values
Browse files Browse the repository at this point in the history
Always set a value to availableProtocols and currentProtocol before any
return in error.

Thanks to Maksim Ivanov for the bug report
"[Pcsclite-muscle] Missing checks of ATRDecodeAtr returns"
https://lists.infradead.org/pipermail/pcsclite-muscle/2020-July/001097.html

" Hello,

The callers of the ATRDecodeAtr() function (SCardConnect() and
SCardReconnect() in winscard.c) don't check its return value, which
might potentially cause reads of uninitialized variables
|availableProtocols| and |defaultProtocol| and unexpected side
effects.

Regards,
Maksim "
  • Loading branch information
LudovicRousseau committed Aug 8, 2020
1 parent 38dfe5c commit a706455
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/atrhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ short ATRDecodeAtr(int *availableProtocols, int *currentProtocol,
LogXxd(PCSC_LOG_DEBUG, "ATR: ", pucAtr, dwLength);
#endif

if (dwLength < 2)
return 0; /** @retval 0 Atr must have TS and T0 */

/*
* Zero out the bitmasks
*/
*availableProtocols = SCARD_PROTOCOL_UNDEFINED;
*currentProtocol = SCARD_PROTOCOL_UNDEFINED;

if (dwLength < 2)
return 0; /** @retval 0 Atr must have TS and T0 */

/*
* Decode the TS byte
*/
Expand Down

0 comments on commit a706455

Please sign in to comment.