channels/smartcard: fix ListReaders mszGroups parsing

This commit is contained in:
Marc-André Moreau 2014-04-08 18:55:50 -04:00
parent d762a284d7
commit 3e4d30df6c
3 changed files with 60 additions and 23 deletions

View File

@ -443,6 +443,7 @@ UINT32 smartcard_unpack_context_call(SMARTCARD_DEVICE* smartcard, wStream* s, Co
UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s, ListReaders_Call* call)
{
UINT32 status;
UINT32 count;
UINT32 mszGroupsNdrPtr;
call->mszGroups = NULL;
@ -460,6 +461,34 @@ UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream*
}
Stream_Read_UINT32(s, call->cBytes); /* cBytes (4 bytes) */
Stream_Read_UINT32(s, mszGroupsNdrPtr); /* mszGroupsNdrPtr (4 bytes) */
Stream_Read_UINT32(s, call->fmszReadersIsNULL); /* fmszReadersIsNULL (4 bytes) */
Stream_Read_UINT32(s, call->cchReaders); /* cchReaders (4 bytes) */
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->Context));
if (status)
return status;
if ((mszGroupsNdrPtr && !call->cBytes) || (!mszGroupsNdrPtr && call->cBytes))
{
WLog_Print(smartcard->log, WLOG_WARN,
"ListReaders_Call mszGroupsNdrPtr (0x%08X) and cBytes (0x%08X) inconsistency",
(int) mszGroupsNdrPtr, (int) call->cBytes);
return STATUS_INVALID_PARAMETER;
}
if (mszGroupsNdrPtr)
{
Stream_Read_UINT32(s, count); /* NdrCount (4 bytes) */
if (count != call->cBytes)
{
WLog_Print(smartcard->log, WLOG_WARN,
"ListReaders_Call NdrCount (0x%08X) and cBytes (0x%08X) inconsistency",
(int) count, (int) call->cBytes);
return STATUS_INVALID_PARAMETER;
}
if (Stream_GetRemainingLength(s) < call->cBytes)
{
@ -468,28 +497,19 @@ UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream*
return STATUS_BUFFER_TOO_SMALL;
}
Stream_Read_UINT32(s, mszGroupsNdrPtr); /* mszGroupsNdrPtr (4 bytes) */
call->mszGroups = (BYTE*) calloc(1, call->cBytes + 4);
Stream_Read_UINT32(s, call->fmszReadersIsNULL); /* fmszReadersIsNULL (4 bytes) */
Stream_Read_UINT32(s, call->cchReaders); /* cchReaders (4 bytes) */
if (Stream_GetRemainingLength(s) < 4)
if (!call->mszGroups)
{
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call is too short: %d",
(int) Stream_GetRemainingLength(s));
return STATUS_BUFFER_TOO_SMALL;
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call out of memory error (mszGroups)");
return STATUS_NO_MEMORY;
}
if (mszGroupsNdrPtr)
{
WLog_Print(smartcard->log, WLOG_WARN, "ListReaders_Call unimplemented mszGroups parsing");
Stream_Read(s, call->mszGroups, call->cBytes);
smartcard_unpack_read_size_align(smartcard, s, call->cBytes, 4);
}
status = smartcard_unpack_redir_scard_context_ref(smartcard, s, &(call->Context));
if (status)
return status;
return SCARD_S_SUCCESS;
}

View File

@ -28,6 +28,8 @@
#include "smartcard_pcsc.h"
static BOOL g_SCardAutoAllocate = FALSE;
static HMODULE g_PCSCModule = NULL;
static PCSCFunctionTable g_PCSC = { 0 };
@ -990,6 +992,7 @@ extern int PCSC_InitializeSCardApi_Link(void);
int PCSC_InitializeSCardApi(void)
{
#if 0
if (PCSC_InitializeSCardApi_Link() >= 0)
{
g_PCSC.pfnSCardEstablishContext = g_PCSC_Link.pfnSCardEstablishContext;
@ -1013,8 +1016,13 @@ int PCSC_InitializeSCardApi(void)
return 1;
}
#endif
#ifdef __MACOSX__
g_PCSCModule = LoadLibraryA("/System/Library/Frameworks/PCSC.framework/PCSC");
#else
g_PCSCModule = LoadLibraryA("libpcsclite.so");
#endif
if (!g_PCSCModule)
return -1;
@ -1033,10 +1041,18 @@ int PCSC_InitializeSCardApi(void)
g_PCSC.pfnSCardTransmit = (void*) GetProcAddress(g_PCSCModule, "SCardTransmit");
g_PCSC.pfnSCardListReaderGroups = (void*) GetProcAddress(g_PCSCModule, "SCardListReaderGroups");
g_PCSC.pfnSCardListReaders = (void*) GetProcAddress(g_PCSCModule, "SCardListReaders");
g_PCSC.pfnSCardFreeMemory = (void*) GetProcAddress(g_PCSCModule, "SCardFreeMemory");
g_PCSC.pfnSCardCancel = (void*) GetProcAddress(g_PCSCModule, "SCardCancel");
g_PCSC.pfnSCardGetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardGetAttrib");
g_PCSC.pfnSCardSetAttrib = (void*) GetProcAddress(g_PCSCModule, "SCardSetAttrib");
g_PCSC.pfnSCardFreeMemory = NULL;
#ifndef __MACOSX__
g_PCSC.pfnSCardFreeMemory = (void*) GetProcAddress(g_PCSCModule, "SCardFreeMemory");
#endif
if (g_PCSC.pfnSCardFreeMemory)
g_SCardAutoAllocate = TRUE;
return 1;
}

View File

@ -20,6 +20,7 @@
#ifndef WINPR_SMARTCARD_PCSC_PRIVATE_H
#define WINPR_SMARTCARD_PCSC_PRIVATE_H
#include <winpr/platform.h>
#include <winpr/smartcard.h>
struct _PCSCFunctionTable