e2fsdroid: Fix crash with invalid command line args.
If a sparse file fails to load, an inconsistent channel pointer will be
returned, causing e2fsdroid to crash on exit.
Bug: 64109868
Test: manual
Change-Id: If1606c7c49d5569323db5b5fce4826f24ba76383
diff --git a/lib/ext2fs/sparse_io.c b/lib/ext2fs/sparse_io.c
index d0828a8..5e0e2cd 100644
--- a/lib/ext2fs/sparse_io.c
+++ b/lib/ext2fs/sparse_io.c
@@ -185,14 +185,22 @@
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,