Fixed SCard debug WCHAR string lengths
authorakallabeth <akallabeth@posteo.net>
Fri, 5 Feb 2021 16:12:52 +0000 (17:12 +0100)
committerakallabeth <akallabeth@users.noreply.github.com>
Thu, 25 Feb 2021 08:51:41 +0000 (09:51 +0100)
(cherry picked from commit a9409221d073e8665a1f27da764d9d042f557e0f)

channels/smartcard/client/smartcard_operations.c
channels/smartcard/client/smartcard_pack.c

index da86ff8..65f8541 100644 (file)
@@ -421,7 +421,7 @@ static LONG smartcard_ListReaderGroupsW_Call(SMARTCARD_DEVICE* smartcard,
        status = ret.ReturnCode =
            SCardListReaderGroupsW(operation->hContext, (LPWSTR)&mszGroups, &cchGroups);
        ret.msz = (BYTE*)mszGroups;
-       ret.cBytes = cchGroups;
+       ret.cBytes = cchGroups * sizeof(WCHAR);
 
        if (status != SCARD_S_SUCCESS)
                return status;
@@ -1719,6 +1719,9 @@ static LONG smartcard_StatusW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERAT
                ret.cbAtrLen = cbAtrLen;
        }
 
+       /* SCardStatusW returns number of characters, we need number of bytes */
+       ret.cBytes *= sizeof(WCHAR);
+
        status = smartcard_pack_status_return(smartcard, irp->output, &ret, TRUE);
        if (status != SCARD_S_SUCCESS)
                return status;
index a85cce6..5532eb2 100644 (file)
@@ -2043,8 +2043,6 @@ LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStre
                                               const ListReaderGroups_Return* ret, BOOL unicode)
 {
        DWORD index = 0;
-       UINT32 size = unicode ? sizeof(WCHAR) : sizeof(CHAR);
-       size *= ret->cBytes;
 
        smartcard_trace_list_reader_groups_return(smartcard, ret, unicode);
        if (ret->ReturnCode != SCARD_S_SUCCESS)
@@ -2053,11 +2051,11 @@ LONG smartcard_pack_list_reader_groups_return(SMARTCARD_DEVICE* smartcard, wStre
        if (!Stream_EnsureRemainingCapacity(s, 4))
                return SCARD_E_NO_MEMORY;
 
-       Stream_Write_UINT32(s, size); /* cBytes (4 bytes) */
-       if (!smartcard_ndr_pointer_write(s, &index, size))
+       Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
+       if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes))
                return SCARD_E_NO_MEMORY;
 
-       return smartcard_ndr_write(s, ret->msz, size, 1, NDR_PTR_SIMPLE);
+       return smartcard_ndr_write(s, ret->msz, ret->cBytes, 1, NDR_PTR_SIMPLE);
 }
 
 LONG smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream* s,
@@ -2658,8 +2656,6 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const
                                   BOOL unicode)
 {
        DWORD index = 0;
-       UINT32 size = unicode ? sizeof(WCHAR) : sizeof(CHAR);
-       size *= ret->cBytes;
 
        smartcard_trace_status_return(smartcard, ret, unicode);
        if (ret->ReturnCode != SCARD_S_SUCCESS)
@@ -2668,8 +2664,8 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const
        if (!Stream_EnsureRemainingCapacity(s, 4))
                return SCARD_F_INTERNAL_ERROR;
 
-       Stream_Write_UINT32(s, size); /* cBytes (4 bytes) */
-       if (!smartcard_ndr_pointer_write(s, &index, size))
+       Stream_Write_UINT32(s, ret->cBytes); /* cBytes (4 bytes) */
+       if (!smartcard_ndr_pointer_write(s, &index, ret->cBytes))
                return SCARD_E_NO_MEMORY;
 
        if (!Stream_EnsureRemainingCapacity(s, 44))
@@ -2679,7 +2675,7 @@ LONG smartcard_pack_status_return(SMARTCARD_DEVICE* smartcard, wStream* s, const
        Stream_Write_UINT32(s, ret->dwProtocol); /* dwProtocol (4 bytes) */
        Stream_Write(s, ret->pbAtr, sizeof(ret->pbAtr)); /* pbAtr (32 bytes) */
        Stream_Write_UINT32(s, ret->cbAtrLen);   /* cbAtrLen (4 bytes) */
-       return smartcard_ndr_write(s, ret->mszReaderNames, size, 1, NDR_PTR_SIMPLE);
+       return smartcard_ndr_write(s, ret->mszReaderNames, ret->cBytes, 1, NDR_PTR_SIMPLE);
 }
 
 LONG smartcard_unpack_get_attrib_call(SMARTCARD_DEVICE* smartcard, wStream* s, GetAttrib_Call* call)