From c84646c105b7ea2b47b58fb470e5222da71323ca Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 23 Nov 2016 18:50:18 +0100 Subject: [PATCH] virt plugin: Avoid NULL pointer deference As per pull request review. Moving the variable assignement after the check avoid any potential issues in the future. Signed-off-by: Francesco Romani --- src/virt.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/virt.c b/src/virt.c index 18112c91..9ca4f0d7 100644 --- a/src/virt.c +++ b/src/virt.c @@ -501,13 +501,16 @@ static int lv_config(const char *key, const char *value) { static int lv_read(user_data_t *ud) { time_t t; - struct lv_read_instance *inst = ud->data; - struct lv_read_state *state = &inst->read_state; - if (!inst) { + struct lv_read_instance *inst = NULL; + struct lv_read_state *state = NULL; + if (ud->data == NULL) { ERROR(PLUGIN_NAME " plugin: NULL userdata"); return -1; } + inst = ud->data; + state = &inst->read_state; + if (inst->id == 0 && conn == NULL) { /* `conn_string == NULL' is acceptable. */ conn = virConnectOpenReadOnly(conn_string); -- 2.30.2