From 8c83f8957be91ab6cdc0c1fea1d716f9fc65945c Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Fri, 20 Oct 2017 13:52:13 +0200 Subject: [PATCH] Fix SCARD_AUTOALLOCATE handling SCARD_AUTOALLOCATE is a define with value -1, which is compared to an uint32. There was some missassumtion of whenever its -1 or 0xffffffff through the code. --- scard.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/scard.c b/scard.c index 6695fd3..766eabf 100644 --- a/scard.c +++ b/scard.c @@ -2028,22 +2028,17 @@ TS_SCardGetAttrib(STREAM in, STREAM out) "TS_SCardGetAttrib(), hcard: 0x%08x [0x%08lx], attrib: 0x%08x (%d bytes)", (unsigned) hCard, (unsigned long) myHCard, (unsigned) dwAttrId, (int) dwAttrLen); - if (dwAttrLen > MAX_BUFFER_SIZE) + pbAttr = NULL; + if (dwAttrLen != (SERVER_DWORD)SCARD_AUTOALLOCATE) + { + if (dwAttrLen > MAX_BUFFER_SIZE) + { dwAttrLen = MAX_BUFFER_SIZE; + } - - if (dwAttrLen > SCARD_AUTOALLOCATE) - pbAttr = NULL; - else if ((dwAttrLen < 0) || (dwAttrLen > SCARD_MAX_MEM)) - { - dwAttrLen = (SERVER_DWORD) SCARD_AUTOALLOCATE; - pbAttr = NULL; - } - else - { - pbAttr = SC_xmalloc(&lcHandle, dwAttrLen); - if (!pbAttr) - return SC_returnNoMemoryError(&lcHandle, in, out); + pbAttr = SC_xmalloc(&lcHandle, dwAttrLen); + if (!pbAttr) + return SC_returnNoMemoryError(&lcHandle, in, out); } attrLen = dwAttrLen;