Whamcloud - gitweb
AOSP: e2fsdroid: Fix crash with invalid command line args
authorDavid Anderson <dvander@google.com>
Fri, 2 Mar 2018 23:38:38 +0000 (15:38 -0800)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 20 Jul 2018 22:49:35 +0000 (18:49 -0400)
If a sparse file fails to load, an inconsistent channel pointer will be
returned, causing e2fsdroid to crash on exit.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Bug: 64109868
Change-Id: If1606c7c49d5569323db5b5fce4826f24ba76383
From AOSP commit: 0f31d29a968eed6dc3c96eb47fd34e8608a2580c

lib/ext2fs/sparse_io.c

index d0828a8..5e0e2cd 100644 (file)
@@ -185,14 +185,22 @@ err_params:
 static errcode_t sparse_open_channel(struct sparse_io_params *sparse_params,
                                     int flags, io_channel *channel)
 {
+       errcode_t retval;
        io_channel io;
 
        io = calloc(1, sizeof(struct struct_io_channel));
        io->magic = EXT2_ET_MAGIC_IO_CHANNEL;
        io->block_size = 0;
        io->refcount = 1;
+
+       retval = io_manager_configure(sparse_params, flags, io);
+       if (retval) {
+               free(io);
+               return retval;
+       }
+
        *channel = io;
-       return io_manager_configure(sparse_params, flags, io);
+       return 0;
 }
 
 static errcode_t read_sparse_argv(const char *name, bool is_fd,