• Stephen Tweedie's avatar
    ext2fs_resize_mem() is suffering from C99 strict type aliasing problems. · 39c191f5
    Stephen Tweedie authored
    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.
    39c191f5
ext2fs.h 33.7 KB