LWN.net Logo

Buggifying critical core modules

Buggifying critical core modules

Posted Mar 19, 2008 18:04 UTC (Wed) by zlynx (subscriber, #2285)
In reply to: Buggifying critical core modules by quotemstr
Parent article: Who maintains dpkg?

I should have kept my response simple.

No, you cannot use NULL everywhere.  If function pointers and data pointers are different
sizes, a void pointer will be the largest size.  This will cause problems with varargs when it
expects a pointer of the smaller size.

An example with 32-bit function and 64-bit data:
After calling the vararg function *properly* the stack might look like:
 (char*)0xf00fdeadf00fdead
 int(*x)(int,int)0xdeadbeef
 (int)32
 (int)64

But if you call it with NULL for the function pointer it will be:
 (char*)0xf00fdeadf00fdead
 (void*)0x0000000000000000
 (int)32
 (int)64

Now if the vararg function pulls the arguments like this:
 pull char* - 0xf00fdeadf00fdead
 pull int(*x)(int,int) - 0x00000000
 pull int - 0
 pull int - 32

See how the last two int arguments got the wrong data?


(Log in to post comments)

Buggifying critical core modules

Posted Mar 19, 2008 18:09 UTC (Wed) by quotemstr (subscriber, #45331) [Link]

Even in the highly unlikely scenario that function pointers someday become _smaller_ than data
pointers (which would have no benefits and which would make dynamic loading exceedingly
complicated and delicate), the vast majority of pointers are still data pointers, all of which
will have the same size.

My point is that in the real world on mainstream systems, you don't have to worry about
contingencies like the kind you mentioned anymore. Embedded, special-purpose code is
different, but then we're not talking about POSIX anymore, and lots of other assumptions go
out the window too.

I don't imagine dpkg is going to run on a microcontroller.

Buggifying critical core modules

Posted Mar 20, 2008 18:53 UTC (Thu) by dododge (subscriber, #2870) [Link]

> If function pointers and data pointers are different
> sizes, a void pointer will be the largest size.

No, as noted above C explicitly requires void* to have the same representation and alignment
as char*.  The guarantee that a pointer can be reliably converted to void* and back again
applies only to pointers to object and incomplete types, not pointers to functions.

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds
Powered by Rackspace Managed Hosting.