[PATCH 2/3] advapi32: Use helper for converting crypt objects handles to pointers.

Paul Gofman pgofman at codeweavers.com
Wed Feb 17 12:28:05 CST 2021


On 2/17/21 18:24, Alexandre Julliard wrote:
> Paul Gofman <pgofman at codeweavers.com> writes:
>
>> @@ -57,6 +57,37 @@ static HWND crypt_hWindow;
>>  #define CRYPT_Alloc(size) (LocalAlloc(LMEM_ZEROINIT, size))
>>  #define CRYPT_Free(buffer) (LocalFree(buffer))
>>  
>> +static void *pointer_from_handle(UINT_PTR handle, DWORD magic, DWORD invalid_handle_error_code)
>> +{
>> +    if (!handle)
>> +    {
>> +        SetLastError(invalid_handle_error_code);
>> +        return NULL;
>> +    }
>> +    if (*(DWORD *)handle != magic)
>> +    {
>> +        SetLastError(ERROR_INVALID_PARAMETER);
>> +        return NULL;
>> +    }
>> +
>> +    return (void *)handle;
>> +}
>> +
>> +static PCRYPTPROV provider_from_handle(HCRYPTPROV handle, DWORD invalid_handle_error_code)
>> +{
>> +    return pointer_from_handle(handle, MAGIC_CRYPTPROV, invalid_handle_error_code);
>> +}
>> +
>> +static PCRYPTHASH hash_from_handle(HCRYPTHASH handle, DWORD invalid_handle_error_code)
>> +{
>> +    return pointer_from_handle(handle, MAGIC_CRYPTHASH, invalid_handle_error_code);
>> +}
>> +
>> +static PCRYPTKEY key_from_handle(HCRYPTKEY handle, DWORD invalid_handle_error_code)
>> +{
>> +    return pointer_from_handle(handle, MAGIC_CRYPTKEY, invalid_handle_error_code);
>> +}
> That's not very nice. I'd suggest to always fail with
> ERROR_INVALID_PARAMETER. The few places that really need a different
> error code can handle it themselves.
>
I've tested all the cases when we are returning the _INVALID_HANDLE for
crypt objects and it looks like it is always _INVALID_PARAMETER on
Windows. I've updated the patches accordingly.




More information about the wine-devel mailing list