From 65d7d83b1c7bd691f4c9ab1564c31cebaaa5408e Mon Sep 17 00:00:00 2001 From: Yonghua Huang Date: Mon, 17 Jun 2019 18:33:03 +0800 Subject: [PATCH] refine 'assert' usage in vmmapi.c and main.c cleanup 'assert' to avoid possible software vulnerabilities Tracked-On: #3252 Signed-off-by: Yonghua Huang Reviewed-by: Shuo A Liu --- devicemodel/core/main.c | 12 ++++++++---- devicemodel/core/vmmapi.c | 9 +++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index 64b332ea1..fcac9a168 100644 --- a/devicemodel/core/main.c +++ b/devicemodel/core/main.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -654,10 +653,15 @@ vm_loop(struct vmctx *ctx) int error; ctx->ioreq_client = vm_create_ioreq_client(ctx); - assert(ctx->ioreq_client > 0); + if (ctx->ioreq_client <= 0) { + pr_err("%s, failed to create IOREQ.\n", __func__); + return; + } - error = vm_run(ctx); - assert(error == 0); + if (vm_run(ctx) != 0) { + pr_err("%s, failed to run VM.\n", __func__); + return; + } while (1) { int vcpu_id; diff --git a/devicemodel/core/vmmapi.c b/devicemodel/core/vmmapi.c index fe2e9390f..44939761e 100644 --- a/devicemodel/core/vmmapi.c +++ b/devicemodel/core/vmmapi.c @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -98,8 +97,8 @@ vm_create(const char *name, uint64_t req_buf) memset(&create_vm, 0, sizeof(struct acrn_create_vm)); ctx = calloc(1, sizeof(struct vmctx) + strnlen(name, PATH_MAX) + 1); - assert(ctx != NULL); - assert(devfd == -1); + if ((ctx == NULL) || (devfd != -1)) + goto err; if (stat("/dev/acrn_vhm", &tmp_st) == 0) { devfd = open("/dev/acrn_vhm", O_RDWR|O_CLOEXEC); @@ -174,7 +173,9 @@ vm_create(const char *name, uint64_t req_buf) return ctx; err: - free(ctx); + if (ctx != NULL) + free(ctx); + return NULL; }