Fix smartcard segfault when no devices are present (#5364)

* Don't assume smartcard reader list is not empty.

* Check status of retrieval of smartcard device list before trying to filter it

* style fixes
This commit is contained in:
r-barnett
2019-05-01 23:11:57 -05:00
committed by akallabeth
parent 84e50582b7
commit 40ef08ddc5

View File

@@ -457,7 +457,7 @@ static DWORD filter_device_by_name_a(wLinkedList* list, LPSTR* mszReaders, DWORD
{
size_t rpos = 0, wpos = 0;
if (LinkedList_Count(list) < 1)
if (*mszReaders == NULL || LinkedList_Count(list) < 1)
return cchReaders;
do
@@ -547,9 +547,6 @@ static LONG smartcard_ListReadersA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_O
cchReaders = SCARD_AUTOALLOCATE;
status = ret.ReturnCode = SCardListReadersA(operation->hContext, (LPCSTR) call->mszGroups,
(LPSTR) &mszReaders, &cchReaders);
cchReaders = filter_device_by_name_a(smartcard->names, &mszReaders, cchReaders);
ret.msz = (BYTE*) mszReaders;
ret.cBytes = cchReaders;
if (call->mszGroups)
{
@@ -563,6 +560,9 @@ static LONG smartcard_ListReadersA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_O
return status;
}
cchReaders = filter_device_by_name_a(smartcard->names, &mszReaders, cchReaders);
ret.msz = (BYTE*) mszReaders;
ret.cBytes = cchReaders;
smartcard_trace_list_readers_return(smartcard, &ret, FALSE);
if ((status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret)))
@@ -610,9 +610,6 @@ static LONG smartcard_ListReadersW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_O
cchReaders = SCARD_AUTOALLOCATE;
status = ret.ReturnCode = SCardListReadersW(operation->hContext,
(LPCWSTR) call->mszGroups, (LPWSTR) &mszReaders, &cchReaders);
cchReaders = filter_device_by_name_w(smartcard->names, &mszReaders, cchReaders);
ret.msz = (BYTE*) mszReaders;
ret.cBytes = cchReaders * 2;
if (call->mszGroups)
{
@@ -626,6 +623,9 @@ static LONG smartcard_ListReadersW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_O
return status;
}
cchReaders = filter_device_by_name_w(smartcard->names, &mszReaders, cchReaders);
ret.msz = (BYTE*) mszReaders;
ret.cBytes = cchReaders * 2;
smartcard_trace_list_readers_return(smartcard, &ret, TRUE);
if ((status = smartcard_pack_list_readers_return(smartcard, irp->output, &ret)))