channels/smartcard: more 64-bit fixes
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Sun, 6 Apr 2014 01:17:54 +0000 (21:17 -0400)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Sun, 6 Apr 2014 01:17:54 +0000 (21:17 -0400)
channels/smartcard/client/smartcard_operations.c
channels/smartcard/client/smartcard_pack.c

index 00e596e..2b1e612 100644 (file)
@@ -165,7 +165,7 @@ static UINT32 handle_Context(SMARTCARD_DEVICE* smartcard, IRP* irp)
                return SCARD_F_INTERNAL_ERROR;
        }
 
-       Stream_Seek(irp->input, length);
+       Stream_Seek_UINT32(irp->input); /* NdrPtr (4 bytes) */
 
        if (length > Stream_GetRemainingLength(irp->input))
        {
@@ -203,7 +203,7 @@ static UINT32 handle_CardHandle(SMARTCARD_DEVICE* smartcard, IRP* irp)
                return SCARD_F_INTERNAL_ERROR;
        }
 
-       Stream_Seek_UINT32(irp->input); /* pbContextNdrPtr (4 bytes) */
+       Stream_Seek_UINT32(irp->input); /* NdrPtr (4 bytes) */
 
        return 0;
 }
@@ -417,8 +417,9 @@ static void smartcard_input_repos(IRP* irp, UINT32 read)
 static UINT32 handle_EstablishContext(SMARTCARD_DEVICE* smartcard, IRP* irp)
 {
        UINT32 status;
-       EstablishContext_Call call;
        SCARDCONTEXT hContext = -1;
+       EstablishContext_Call call;
+       EstablishContext_Return ret;
 
        status = smartcard_unpack_establish_context_call(smartcard, irp->input, &call);
 
@@ -427,13 +428,18 @@ static UINT32 handle_EstablishContext(SMARTCARD_DEVICE* smartcard, IRP* irp)
 
        status = SCardEstablishContext(call.dwScope, NULL, NULL, &hContext);
 
-       Stream_Write_UINT32(irp->output, 4); /* cbContext (4 bytes) */
-       Stream_Write_UINT32(irp->output, -1); /* ReferentID (4 bytes) */
+       ret.Context.cbContext = sizeof(SCARDCONTEXT);
+
+       Stream_Write_UINT32(irp->output, ret.Context.cbContext); /* cbContext (4 bytes) */
+       Stream_Write_UINT32(irp->output, 0x00020000); /* pbContextNdrPtr (4 bytes) */
 
-       Stream_Write_UINT32(irp->output, 4);
-       Stream_Write_UINT32(irp->output, hContext);
+       Stream_Write_UINT32(irp->output, ret.Context.cbContext);
+
+       if (ret.Context.cbContext > 4)
+               Stream_Write_UINT64(irp->output, hContext);
+       else
+               Stream_Write_UINT32(irp->output, hContext);
 
-       /* store hContext in allowed context list */
        smartcard->hContext = hContext;
 
        smartcard_output_alignment(irp, 8);
@@ -1507,7 +1513,7 @@ static UINT32 handle_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp)
                return status;
 
        ret.pbAttr = NULL;
-       cbAttrLen = (call.cbAttrLen == 0) ? 0 : SCARD_AUTOALLOCATE;
+       cbAttrLen = (!call.cbAttrLen || call.fpbAttrIsNULL) ? 0 : SCARD_AUTOALLOCATE;
 
        status = SCardGetAttrib(hCard, call.dwAttrId, (cbAttrLen == 0) ? NULL : (BYTE*) &ret.pbAttr, &cbAttrLen);
 
@@ -1554,7 +1560,7 @@ static UINT32 handle_GetAttrib(SMARTCARD_DEVICE* smartcard, IRP* irp)
                ret.cbAttrLen = call.cbAttrLen;
 
                Stream_Write_UINT32(irp->output, ret.cbAttrLen); /* cbAttrLen (4 bytes) */
-               Stream_Write_UINT32(irp->output, 0x00000200); /* pbAttrPointer (4 bytes) */
+               Stream_Write_UINT32(irp->output, 0x00020000); /* pbAttrPointer (4 bytes) */
                Stream_Write_UINT32(irp->output, ret.cbAttrLen); /* pbAttrLength (4 bytes) */
 
                if (!ret.pbAttr)
index 48a2951..b1f07d5 100644 (file)
@@ -156,7 +156,7 @@ UINT32 smartcard_unpack_list_readers_call(SMARTCARD_DEVICE* smartcard, wStream*
        }
 
        call->mszGroups = NULL;
-       Stream_Seek(s, 4); /* mszGroupsPtr (4 bytes) */
+       Stream_Seek_UINT32(s); /* mszGroupsNdrPtr (4 bytes) */
 
        Stream_Read_UINT32(s, call->fmszReadersIsNULL); /* fmszReadersIsNULL (4 bytes) */
        Stream_Read_UINT32(s, call->cchReaders); /* cchReaders (4 bytes) */