Re: zend_hash_add_or_update flaw

From: Date: Wed, 06 Dec 2000 20:49:48 +0000
Subject: Re: zend_hash_add_or_update flaw
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-40252@lists.php.net to get a copy of this message
At 09:26 PM 12/6/00 +0100, Sascha Schumann wrote:
On Wed, 6 Dec 2000, Andi Gutmans wrote: I don't quite understand what flaw you are talking about. pDataPtr is a void *. If the size of the data we are receiving is the same size of pDataPtr (sizeof(void *)) we copy it's value to pDataPtr. I don't see why doing it via a cast doesn't work. It should work on all platforms. pDataPtr = *(void **)pData (where pData is the size of void *). What your patch does isn't fixing a flaw (unless I'm missing something) but adding functionality by using pDataPtr even if pData is smaller than void *. If I'd know that on all systems memcpy() is as fast as doing it with a cast I wouldn't mind the patch but I am pretty sure it isn't.
    It looks like an alignment problem.
    While memcpy handles unaligned accesses to memory properly,
    the cast will generate code which assumes that pData is
    properly aligned.
    Testcase attached.
    $ gcc x.c
    $ ./a.out
    ffbefc60
    ffbefc61
    Bus Error (core dumped)
    $ uname -m
    sun4u
Right. It doesn't work with unaligned data but did you actually bump into such a case in PHP? I prefer not moving to memcpy() unless this is actually the case. Andi --- Andi Gutmans <andi@zend.com> http://www.zend.com/

« previous php.dev (#40252) next »