master - lib: fix init error handling
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=87d9406725b23e6c01e55014606ff047d7375951 Commit: 87d9406725b23e6c01e55014606ff047d7375951 Parent: a6203657a0bf4b15017724a8212cc61a8672afa5 Author: David Teigland <[email protected]> AuthorDate: Thu May 12 13:00:33 2016 -0500 Committer: David Teigland <[email protected]> CommitterDate: Thu May 12 13:07:52 2016 -0500
lib: fix init error handling
When setting up a toolcontext, the lib init function was detecting an error when there was none, and then it was returning an incompletely initialized cmd struct instead of NULL. The effect was that the lib would try to use the uninitialized cmd struct and segfault. This would happen if a non-fatal error occurred during cmd setup, e.g. user permission failed on lvmetad socket, causing cmd to fall back to scanning and not use lvmetad.
The only real error condition is when create_toolcontext returns NULL. If cmd is returned, the lib can use it.
--- lib/commands/toolcontext.c | 2 +- liblvm/lvm_base.c | 3 --- 2 files changed, 1 insertions(+), 4 deletions(-)
lib/commands/toolcontext.c +1 -1
@@ -1945,7 +1945,7 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,_init_globals (cmd);if (set_connections && !init_connections (cmd)) - return_0; + goto_out;if (set_filters && !init_filters (cmd,1 )) goto_out;
liblvm/lvm_base.c +0 -3
@@ -49,9 +49,6 @@ static lvm_t _lvm_init(const char *system_dir)if (!cmd)return NULL ; -if (stored_errno ()) -return (lvm_t ) cmd; -/* * FIXME: if an non memory error occured, return the cmd (maybe some * cleanup needed).