pcsc-lite/0003-ATRDecodeAtr-always-initialize-the-return-values.patch

53 lines
1.4 KiB
Diff
Raw Normal View History

From a706455f31178ab35f07e3e6e76bd4a35d7ef3da Mon Sep 17 00:00:00 2001
From: Ludovic Rousseau <ludovic.rousseau@free.fr>
Date: Sat, 8 Aug 2020 15:11:53 +0200
Subject: [PATCH 03/13] ATRDecodeAtr: always initialize the return values
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"
http://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 "
---
src/atrhandler.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/atrhandler.c b/src/atrhandler.c
index 2ebc440..1e0654d 100644
--- a/src/atrhandler.c
+++ b/src/atrhandler.c
@@ -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
*/
--
1.8.3.1