Skip to content

Commit 65d7d83

Browse files
yonghuahwenlingz
authored andcommitted
refine 'assert' usage in vmmapi.c and main.c
cleanup 'assert' to avoid possible software vulnerabilities Tracked-On: #3252 Signed-off-by: Yonghua Huang <yonghua.huang@intel.com> Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
1 parent dedf9be commit 65d7d83

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

devicemodel/core/main.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
#include <errno.h>
3434
#include <libgen.h>
3535
#include <unistd.h>
36-
#include <assert.h>
3736
#include <pthread.h>
3837
#include <sysexits.h>
3938
#include <stdbool.h>
@@ -654,10 +653,15 @@ vm_loop(struct vmctx *ctx)
654653
int error;
655654

656655
ctx->ioreq_client = vm_create_ioreq_client(ctx);
657-
assert(ctx->ioreq_client > 0);
656+
if (ctx->ioreq_client <= 0) {
657+
pr_err("%s, failed to create IOREQ.\n", __func__);
658+
return;
659+
}
658660

659-
error = vm_run(ctx);
660-
assert(error == 0);
661+
if (vm_run(ctx) != 0) {
662+
pr_err("%s, failed to run VM.\n", __func__);
663+
return;
664+
}
661665

662666
while (1) {
663667
int vcpu_id;

devicemodel/core/vmmapi.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <stdio.h>
3333
#include <stdlib.h>
3434
#include <stdbool.h>
35-
#include <assert.h>
3635
#include <string.h>
3736
#include <ctype.h>
3837
#include <fcntl.h>
@@ -98,8 +97,8 @@ vm_create(const char *name, uint64_t req_buf)
9897

9998
memset(&create_vm, 0, sizeof(struct acrn_create_vm));
10099
ctx = calloc(1, sizeof(struct vmctx) + strnlen(name, PATH_MAX) + 1);
101-
assert(ctx != NULL);
102-
assert(devfd == -1);
100+
if ((ctx == NULL) || (devfd != -1))
101+
goto err;
103102

104103
if (stat("/dev/acrn_vhm", &tmp_st) == 0) {
105104
devfd = open("/dev/acrn_vhm", O_RDWR|O_CLOEXEC);
@@ -174,7 +173,9 @@ vm_create(const char *name, uint64_t req_buf)
174173
return ctx;
175174

176175
err:
177-
free(ctx);
176+
if (ctx != NULL)
177+
free(ctx);
178+
178179
return NULL;
179180
}
180181

0 commit comments

Comments
 (0)