]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfsprogs: libxcmd: don't clobber fs_table on realloc()
authorAlex Elder <aelder@sgi.com>
Wed, 28 Sep 2011 10:57:08 +0000 (10:57 +0000)
committerAlex Elder <aelder@sgi.com>
Thu, 29 Sep 2011 14:30:45 +0000 (09:30 -0500)
In fs_table_insert(), realloc() is called to resize the global
fs_table.  If it fails, it overwrites a previously valid fs_table
pointer with NULL.

Instead, assign the return value to a local temporary and overwrite
fs_table only if the realloc() call succeeds.  The only defined
errno value for a realloc() failure is ENOMEM, so return that
explicitly in the event it fails.

Signed-off-by: Alex Elder <aelder@sgi.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxcmd/paths.c

index 1dbe0be801bb3a24c9948258c1618a497e1c0d25..0e02eb7103ed8a2ac6505ced38af3050af915029 100644 (file)
@@ -102,6 +102,7 @@ fs_table_insert(
        char            *fsrt)
 {
        dev_t           datadev, logdev, rtdev;
+       struct fs_path  *tmp_fs_table;
 
        if (!dir || !fsname)
                return EINVAL;
@@ -114,9 +115,10 @@ fs_table_insert(
        if (fsrt && (fsrt = fs_device_number(fsrt, &rtdev, 1)) == NULL)
                return errno;
 
-       fs_table = realloc(fs_table, sizeof(fs_path_t) * (fs_count + 1));
-       if (!fs_table)
-               return errno;
+       tmp_fs_table = realloc(fs_table, sizeof(fs_path_t) * (fs_count + 1));
+       if (!tmp_fs_table)
+               return ENOMEM;
+       fs_table = tmp_fs_table;
 
        fs_path = &fs_table[fs_count];
        fs_path->fs_dir = dir;