Whamcloud - gitweb
ext2fs_resize_mem() is suffering from C99 strict type aliasing problems.
authorStephen Tweedie <sct@redhat.com>
Mon, 27 Jun 2005 15:47:21 +0000 (11:47 -0400)
committerStephen Tweedie <sct@redhat.com>
Mon, 27 Jun 2005 15:47:21 +0000 (11:47 -0400)
commit39c191f5b3bffc5aee56d6335fe54041c582e05d
tree421aa80de92c1ebb7b747fef6a21090851cd5945
parentd9781cee2d1331280dbd13d49989498a3ca7c2a8
ext2fs_resize_mem() is suffering from C99 strict type aliasing problems.
The trouble is that it is modifying pointers in place, but doing so via
"void *" types which alias the pointers passed in (which are typically
pointers to a struct.)  The inline ext2fs_resize_mem() code may update
the pointer, but the caller is not required to reload the old value it
may have cached in a register, according to the type aliasing rules.

This is causing the caller to dereference the old pointer when compiled
with -O2, resulting in reproducible SEGV, on at least one ia64
configuration.

The compiler *is* required to reload if it sees an update to a dereferenced
char value, though, as chars are defined to alias anything; and memcpy()
is defined to operate on chars.  So using memcpy() to copy the pointer
values is guaranteed to force the caller to reload.  This has been
verified to fix the problem in practice.

Fixes Red Hat bug #161183.
lib/ext2fs/ChangeLog
lib/ext2fs/ext2fs.h