Skip to content

Commit

Permalink
libpcscspy: dump an output buffer only if the call succeeded
Browse files Browse the repository at this point in the history
If the PC/SC call failed then the output buffer contains garbage and the
size could be wrong.
  • Loading branch information
LudovicRousseau committed May 22, 2024
1 parent 62ca7e8 commit 6243772
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/spy/libpcscspy.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,12 @@ PCSC_API LONG SCardControl(SCARDHANDLE hCard,
rv = spy.SCardControl(hCard, dwControlCode, pbSendBuffer, cbSendLength,
pbRecvBuffer, cbRecvLength, lpBytesReturned);
if (lpBytesReturned)
spy_buffer(pbRecvBuffer, *lpBytesReturned);
{
if (SCARD_S_SUCCESS == rv)
spy_buffer(pbRecvBuffer, *lpBytesReturned);
else
spy_buffer(NULL, *lpBytesReturned);
}
else
spy_buffer(NULL, 0);
Quit();
Expand Down Expand Up @@ -603,7 +608,12 @@ PCSC_API LONG SCardTransmit(SCARDHANDLE hCard,
spy_long(-1);
}
if (pcbRecvLength)
spy_buffer(pbRecvBuffer, *pcbRecvLength);
{
if (SCARD_S_SUCCESS == rv)
spy_buffer(pbRecvBuffer, *pcbRecvLength);
else
spy_buffer(NULL, *pcbRecvLength);
}
else
spy_buffer(NULL, 0);
Quit();
Expand Down Expand Up @@ -697,16 +707,19 @@ PCSC_API LONG SCardGetAttrib(SCARDHANDLE hCard,
if (NULL == pcbAttrLen)
spy_buffer(NULL, 0);
else
{
LPBYTE buffer;

if (autoallocate)
buffer = *(LPBYTE *)pbAttr;
if (rv != SCARD_S_SUCCESS)
spy_buffer(NULL, *pcbAttrLen);
else
buffer = pbAttr;
{
LPBYTE buffer;

spy_buffer(buffer, *pcbAttrLen);
}
if (autoallocate)
buffer = *(LPBYTE *)pbAttr;
else
buffer = pbAttr;

spy_buffer(buffer, *pcbAttrLen);
}
Quit();
return rv;
}
Expand Down

0 comments on commit 6243772

Please sign in to comment.