From: "Radim Krčmář" <rkrcmar@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0
Date: Fri, 10 Jul 2015 19:21:27 +0200 [thread overview]
Message-ID: <20150710172127.GA2448@potion> (raw)
In-Reply-To: <CAFEAcA_hfHxXngmx6BErxtgwvDos7VFGBrZP-RoxswT7hEDvig@mail.gmail.com>
2015-07-10 14:56+0100, Peter Maydell:
> On 10 July 2015 at 14:38, Peter Maydell <peter.maydell@linaro.org> wrote:
>> On 10 July 2015 at 14:31, Radim Krčmář <rkrcmar@redhat.com> 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.
next prev parent reply other threads:[~2015-07-10 17:21 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-10 12:33 [Qemu-devel] [PATCH] crypt: fix build with nettle >= 3.0.0 Radim Krčmář
2015-07-10 12:56 ` Peter Maydell
2015-07-10 13:31 ` Radim Krčmář
2015-07-10 13:38 ` Peter Maydell
2015-07-10 13:56 ` Peter Maydell
2015-07-10 17:21 ` Radim Krčmář [this message]
2015-07-10 13:59 ` Radim Krčmář
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150710172127.GA2448@potion \
--to=rkrcmar@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).