qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0


From: Radim Krčmář
Subject: Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0
Date: Fri, 10 Jul 2015 19:21:27 +0200

2015-07-10 14:56+0100, Peter Maydell:
> On 10 July 2015 at 14:38, Peter Maydell <address@hidden> wrote:
>> On 10 July 2015 at 14:31, Radim Krčmář <address@hidden> wrote:
>>> We pass 'ctx' as a 'void *' in the code, but these functions accept
>>> specialized structures, which makes them incompatible:
>>>
>>>   void nettle_cipher_func(const void *ctx, size_t length, [...])
>>>
>>>   void aes_decrypt(const struct aes_ctx *ctx, size_t length, [...])
>>>   void des_decrypt(const struct des_ctx *ctx, size_t length, [...])
>>
>> But aren't both the typedef and the aes/des_decrypt functions
>> provided by the nettle library? Why is the library providing
>> functions whose prototypes don't match its own typedef?
> 
> I had a suspicion that this was undefined behaviour,
> and I was right:
> 
> http://stackoverflow.com/questions/559581/casting-a-function-pointer-to-another-type/14044244#14044244
> 
> If you have a function that takes "const struct foo *f"
> but the library code is calling it using a function pointer
> whose type says it's "const void *", then you can't just cast
> the function pointer before handing it to the library.
> You need to provide the obvious wrapper:
> 
> void aes_decrypt_wrapper(const void *ctx, size_t length, ...)
> {
>     aes_decrypt(ctx, length, ...);
> }

Makes sense, thanks.  'void *' shenanigans got me on this one.

(Btw. the library isn't casting it back to the original type before
 calling and its test cases don't use wrappers.)

I've posted v2 that addresses this problem.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]