From 59377fce5e0c72be033822994a7f249609d6ca16 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 18 Feb 2021 16:48:09 +0100 Subject: [PATCH] Fixed smartcard crash on error return (invalid length) --- channels/smartcard/client/smartcard_pack.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/channels/smartcard/client/smartcard_pack.c b/channels/smartcard/client/smartcard_pack.c index 03d6c8eb3..351be9681 100644 --- a/channels/smartcard/client/smartcard_pack.c +++ b/channels/smartcard/client/smartcard_pack.c @@ -1275,13 +1275,18 @@ static void smartcard_trace_status_return(SMARTCARD_DEVICE* smartcard, const Sta { char* mszReaderNamesA = NULL; char buffer[1024]; + DWORD cBytes; WINPR_UNUSED(smartcard); if (!WLog_IsLevelActive(WLog_Get(TAG), g_LogLevel)) return; - - mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, ret->cBytes, unicode); + cBytes = ret->cBytes; + if (ret->ReturnCode != SCARD_S_SUCCESS) + cBytes = 0; + if (cBytes == SCARD_AUTOALLOCATE) + cBytes = 0; + mszReaderNamesA = smartcard_convert_string_list(ret->mszReaderNames, cBytes, unicode); WLog_LVL(TAG, g_LogLevel, "Status%s_Return {", unicode ? "W" : "A"); WLog_LVL(TAG, g_LogLevel, " ReturnCode: %s (0x%08" PRIX32 ")",