From d96ec7e30fffe389aadd6872e3a9ed46faeec7af Mon Sep 17 00:00:00 2001 From: Kitae Kim Date: Fri, 28 Mar 2014 10:27:53 +0900 Subject: [PATCH] qemu: fix dereference before null check Change-Id: I750bf92f87ed2103f696ba3f8812075744941722 Signed-off-by: Kitae Kim --- blockdev.c | 5 +++-- tizen/src/maru_err_table.c | 13 +++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/blockdev.c b/blockdev.c index 9a4a8fbde2..84a48a0ebf 100644 --- a/blockdev.c +++ b/blockdev.c @@ -522,10 +522,11 @@ static DriveInfo *blockdev_init(QDict *bs_opts, if (ret < 0) { #ifdef CONFIG_MARU const char _msg[] = "Failed to load disk file from the following path. Check if the file is corrupted or missing.\n\n"; - char* err_msg = NULL; + char* err_msg = NULL; + err_msg = maru_convert_path((char*)_msg, file); - start_simple_client(err_msg); if (err_msg) { + start_simple_client(err_msg); g_free(err_msg); } #endif diff --git a/tizen/src/maru_err_table.c b/tizen/src/maru_err_table.c index 508a70ae31..29f55d699d 100644 --- a/tizen/src/maru_err_table.c +++ b/tizen/src/maru_err_table.c @@ -166,6 +166,11 @@ char *maru_convert_path(char *msg, const char *path) total_len += (path_len + msg_len); err_msg = g_malloc0(total_len * sizeof(char)); + if (!err_msg) { + fprintf(stderr, "failed to allocate a buffer for an error massage\n"); + g_free(current_path); + return NULL; + } if (msg) { snprintf(err_msg, msg_len, "%s", msg); @@ -188,9 +193,7 @@ char *maru_convert_path(char *msg, const char *path) if (!dos_err_msg) { fprintf(stderr, "failed to duplicate an error message from %p\n", err_msg); - if (current_path) { - g_free(current_path); - } + g_free(current_path); g_free(err_msg); return NULL; } @@ -204,9 +207,7 @@ char *maru_convert_path(char *msg, const char *path) g_free(dos_err_msg); } #endif - if (current_path) { - g_free(current_path); - } + g_free(current_path); return err_msg; } -- 2.34.1