Fixed smartcard related warnings

This commit is contained in:
Armin Novak 2021-06-18 10:55:09 +02:00 committed by akallabeth
parent 3831233301
commit 4dfee30934
3 changed files with 42 additions and 23 deletions

View File

@ -2428,8 +2428,8 @@ LONG smartcard_irp_device_control_call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OP
LONG result;
UINT32 offset;
UINT32 ioControlCode;
UINT32 outputBufferLength;
UINT32 objectBufferLength;
size_t outputBufferLength;
size_t objectBufferLength;
irp = operation->irp;
ioControlCode = operation->ioControlCode;
/**
@ -2684,14 +2684,19 @@ LONG smartcard_irp_device_control_call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OP
}
Stream_SealLength(irp->output);
outputBufferLength = Stream_Length(irp->output) - RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4;
outputBufferLength = Stream_Length(irp->output);
WINPR_ASSERT(outputBufferLength >= RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4U);
outputBufferLength -= RDPDR_DEVICE_IO_RESPONSE_LENGTH - 4U;
WINPR_ASSERT(outputBufferLength >= RDPDR_DEVICE_IO_RESPONSE_LENGTH);
objectBufferLength = outputBufferLength - RDPDR_DEVICE_IO_RESPONSE_LENGTH;
WINPR_ASSERT(outputBufferLength <= UINT32_MAX);
WINPR_ASSERT(objectBufferLength <= UINT32_MAX);
Stream_SetPosition(irp->output, RDPDR_DEVICE_IO_RESPONSE_LENGTH);
/* Device Control Response */
Stream_Write_UINT32(irp->output, outputBufferLength); /* OutputBufferLength (4 bytes) */
Stream_Write_UINT32(irp->output, (UINT32)outputBufferLength); /* OutputBufferLength (4 bytes) */
smartcard_pack_common_type_header(smartcard, irp->output); /* CommonTypeHeader (8 bytes) */
smartcard_pack_private_type_header(smartcard, irp->output,
objectBufferLength); /* PrivateTypeHeader (8 bytes) */
smartcard_pack_private_type_header(
smartcard, irp->output, (UINT32)objectBufferLength); /* PrivateTypeHeader (8 bytes) */
Stream_Write_INT32(irp->output, result); /* Result (4 bytes) */
Stream_SetPosition(irp->output, Stream_Length(irp->output));
return SCARD_S_SUCCESS;

View File

@ -355,11 +355,13 @@ static char* smartcard_convert_string_list(const void* in, size_t bytes, BOOL un
if (unicode)
{
length = (bytes / sizeof(WCHAR)) - 1;
WINPR_ASSERT(length < INT_MAX);
mszA = (char*)calloc(length + 1, sizeof(WCHAR));
if (!mszA)
return NULL;
if (ConvertFromUnicode(CP_UTF8, 0, string.wz, (int)length, &mszA, length + 1, NULL, NULL) !=
(int)length)
if (ConvertFromUnicode(CP_UTF8, 0, string.wz, (int)length, &mszA, (int)length + 1, NULL,
NULL) != (int)length)
{
free(mszA);
return NULL;
@ -1473,7 +1475,7 @@ static void smartcard_trace_connect_return(SMARTCARD_DEVICE* smartcard, const Co
WLog_LVL(TAG, g_LogLevel, "}");
}
void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, const Reconnect_Call* call)
static void smartcard_trace_reconnect_call(SMARTCARD_DEVICE* smartcard, const Reconnect_Call* call)
{
WINPR_UNUSED(smartcard);

View File

@ -38,6 +38,7 @@
#include <stdlib.h>
#include <winpr/crt.h>
#include <winpr/assert.h>
#include <winpr/synch.h>
#include <winpr/library.h>
#include <winpr/smartcard.h>
@ -1936,7 +1937,10 @@ static LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard, LPSTR mszReaderN
*pcbAtrLen = (DWORD)pcsc_cbAtrLen;
if (pcchReaderLen)
*pcchReaderLen = pcsc_cchReaderLen + 1u;
{
WINPR_ASSERT(pcsc_cchReaderLen < UINT32_MAX);
*pcchReaderLen = (DWORD)pcsc_cchReaderLen + 1u;
}
return (LONG)status;
out_fail:
@ -1956,8 +1960,9 @@ static LONG WINAPI PCSC_SCardState(SCARDHANDLE hCard, LPDWORD pdwState, LPDWORD
DWORD pcsc_dwState = 0;
DWORD pcsc_dwProtocol = 0;
DWORD pcsc_cbAtrLen = 0;
if (pcbAtrLen)
pcsc_cbAtrLen = (PCSC_DWORD)*pcbAtrLen;
pcsc_cbAtrLen = (DWORD)*pcbAtrLen;
if (!g_PCSC.pfnSCardStatus)
return PCSC_SCard_LogError("g_PCSC.pfnSCardStatus");
@ -2352,8 +2357,9 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
if (cbAttrLen == SCARD_AUTOALLOCATE)
{
WINPR_ASSERT(length <= UINT32_MAX / 2);
*conv.ppw = friendlyNameW;
*pcbAttrLen = length * 2;
*pcbAttrLen = (UINT32)length * 2U;
PCSC_AddMemoryBlock(hContext, friendlyNameW);
}
else
@ -2362,8 +2368,9 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
status = SCARD_E_INSUFFICIENT_BUFFER;
else
{
WINPR_ASSERT(length <= UINT32_MAX / 2);
CopyMemory(pbAttr, (BYTE*)friendlyNameW, (length * 2));
*pcbAttrLen = length * 2;
*pcbAttrLen = (UINT32)length * 2U;
}
free(friendlyNameW);
}
@ -2375,7 +2382,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
if (cbAttrLen == SCARD_AUTOALLOCATE)
{
*conv.ppb = (BYTE*)namePCSC;
*pcbAttrLen = length;
WINPR_ASSERT(length <= UINT32_MAX);
*pcbAttrLen = (UINT32)length;
PCSC_AddMemoryBlock(hContext, namePCSC);
}
else
@ -2385,7 +2393,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA
else
{
CopyMemory(pbAttr, namePCSC, length + 1);
*pcbAttrLen = length;
WINPR_ASSERT(length <= UINT32_MAX);
*pcbAttrLen = (UINT32)length;
}
free(namePCSC);
}
@ -2464,7 +2473,11 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
vendorName = (char*)pbAttr;
if (vendorName)
*pcbAttrLen = strnlen(vendorName, *pcbAttrLen);
{
size_t len = strnlen(vendorName, *pcbAttrLen);
WINPR_ASSERT(len <= UINT32_MAX);
*pcbAttrLen = (DWORD)len;
}
else
*pcbAttrLen = 0;
}
@ -2489,14 +2502,13 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
union {
BYTE* pb;
LPDWORD pd;
} conv;
conv.pb = pbAttr;
} conv1;
conv1.pb = pbAttr;
if (cbAttrLen < sizeof(DWORD))
return SCARD_E_INSUFFICIENT_BUFFER;
*conv.pd = PCSC_ConvertProtocolsToWinSCard(dwProtocol);
*conv1.pd = PCSC_ConvertProtocolsToWinSCard(dwProtocol);
*pcbAttrLen = sizeof(DWORD);
}
}
@ -2511,14 +2523,14 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE
BYTE* pb;
BYTE** ppb;
DWORD* ppd;
} conv;
} conv1;
conv.pb = pbAttr;
conv1.pb = pbAttr;
if (cbAttrLen < sizeof(DWORD))
return SCARD_E_INSUFFICIENT_BUFFER;
status = SCARD_S_SUCCESS;
*conv.ppd = (channelType << 16u) | channelNumber;
*conv1.ppd = (channelType << 16u) | channelNumber;
*pcbAttrLen = sizeof(DWORD);
}
}