cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_easy_setopt() typechecker, try2

From: Brian Dessent <brian_at_dessent.net>
Date: Sat, 01 Mar 2008 19:14:02 -0800

Daniel Stenberg wrote:

> > The caller may pass a 32-bit value on the stack, and the callee parse a
> > 64-bit value from the stack, so 32 bits of the value seen in the callee can
> > be garbage. In this case, if you passed FALSE, the callee might interpret
> > it as TRUE instead. Not what you want, a real bug.
>
> Yes, and it is in fact a bit curious that this hasn't bitten us more. Why is
> that? Do 64bit archs typically pass on 64bit values on the stack?

On x86_64 Linux, the calling convention is that up to the first six
arguments that are <= 64 bits are extended to 64 bits and passed in
registers %rdi, %rsi, %rdx, %rcx, %r8 and %r9 in that order. If all
args fit in registers, then nothing is put on the stack. So in this
case the potential type mismatch is not an issue because the TRUE will
be extended to 64 bits and passed in %rdx regardless of whether it was
(int)1 or (long)1. But I could see how it would certainly make sense to
change TRUE to be 1L (assuming va_arg(ap,long) is used on the other end)
just for correctness. I don't know about any other 64 bit arches.

Brian
Received on 2008-03-02