OSDN Git Service

Fix type punning bugs in ext2fs_get_mem() and ext2fs_free_mem()
authorTheodore Ts'o <tytso@mit.edu>
Tue, 14 Nov 2006 05:34:34 +0000 (00:34 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 14 Nov 2006 05:34:34 +0000 (00:34 -0500)
This was causing dumpe2fs to crash on the ARM platform when examining
the badblocks list.

Also reverts an incorrect fix made by changeset 38078f692c20

Addresses Debian Bug: #397044

lib/ext2fs/ChangeLog
lib/ext2fs/badblocks.c
lib/ext2fs/ext2fs.h

index 4a15a4f..30fda66 100644 (file)
@@ -1,3 +1,9 @@
+2006-11-14  Theodore Tso  <tytso@mit.edu>
+
+       * ext2fs.h (ext2fs_get_mem, ext2fs_free_mem): Avoid type punning
+               which causes problems on the ARM processor.  (Addresses
+               Debian Bug: #397044)
+
 2006-11-12  Theodore Tso  <tytso@mit.edu>
 
        * ext2_fs.h (EXT2_FLAG_SOFTSUPP_FEATURES), openfs.c
@@ -8,15 +14,6 @@
        * ext3_extents.h, ext2fs.h: Check in ext4 extent headers into the
                source tree, in preparation for adding full extent support.
 
-       * badblocks.c (make_u32_list): Add workaround for GCC bug (ARM,
-               gcc version 4.1.1-17).  The inline function involved is
-               used all over the e2fsprogs sources, so hopefully this bug
-               won't hit us in other places, but with this one change the
-               e2fsprogs regression test suite is passing, so we'll cross
-               our fingers, report the GCC bug, and hope that it doesn't
-               cause any data corruption/loss.  (Addresses Debian Bug:
-               #397044; Gcc bug reported as Debian Bug #398316)
-
        * unix_io.c (unix_flush): Allow offsets greater than 2G.
                (Addresses SourceForge Bug #1547922)
 
index 42e33bf..50e6336 100644 (file)
 #include "ext2_fs.h"
 #include "ext2fsP.h"
 
-#ifdef __arm__
-#define BUGGY_ARM_GCC
-#endif
-
 /*
  * Helper function for making a badblocks list
  */
@@ -46,19 +42,11 @@ static errcode_t make_u32_list(int size, int num, __u32 *list,
        bb->magic = EXT2_ET_MAGIC_BADBLOCKS_LIST;
        bb->size = size ? size : 10;
        bb->num = num;
-#ifdef BUGGY_ARM_GCC
-       bb->list = malloc(bb->size * sizeof(blk_t));
-       if (!bb->list) {
-               free(bb);
-               return EXT2_ET_NO_MEMORY;
-       }
-#else
        retval = ext2fs_get_mem(bb->size * sizeof(blk_t), &bb->list);
-       if (!bb->list) {
+       if (retval) {
                ext2fs_free_mem(&bb);
                return retval;
        }
-#endif
        if (list)
                memcpy(bb->list, list, bb->size * sizeof(blk_t));
        else
index f4214c2..0889cec 100644 (file)
@@ -1007,11 +1007,12 @@ extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
  */
 _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
 {
-       void **pp = (void **)ptr;
+       void *pp;
 
-       *pp = malloc(size);
-       if (!*pp)
+       pp = malloc(size);
+       if (!pp)
                return EXT2_ET_NO_MEMORY;
+       memcpy(ptr, &pp, sizeof (pp));
        return 0;
 }
 
@@ -1020,10 +1021,12 @@ _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr)
  */
 _INLINE_ errcode_t ext2fs_free_mem(void *ptr)
 {
-       void **pp = (void **)ptr;
+       void *p;
 
-       free(*pp);
-       *pp = 0;
+       memcpy(&p, ptr, sizeof(p));
+       free(p);
+       p = 0;
+       memcpy(ptr, &p, sizeof(p));
        return 0;
 }
        
@@ -1037,11 +1040,11 @@ _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_siz
 
        /* Use "memcpy" for pointer assignments here to avoid problems
         * with C99 strict type aliasing rules. */
-       memcpy(&p, ptr, sizeof (p));
+       memcpy(&p, ptr, sizeof(p));
        p = realloc(p, size);
        if (!p)
                return EXT2_ET_NO_MEMORY;
-       memcpy(ptr, &p, sizeof (p));
+       memcpy(ptr, &p, sizeof(p));
        return 0;
 }
 #endif /* Custom memory routines */