Skip to content

Commit e6eef9b

Browse files
yonghuahwenlingz
authored andcommitted
dm: refine 'assert' usage in pm.c and acpi.c
'assert' usage cleanup 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 885d503 commit e6eef9b

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

devicemodel/arch/x86/pm.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <sys/cdefs.h>
2929
#include <sys/types.h>
3030
#include <stdio.h>
31-
#include <assert.h>
3231
#include <errno.h>
3332
#include <pthread.h>
3433
#include <signal.h>
@@ -69,7 +68,6 @@ static int
6968
reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
7069
uint32_t *eax, void *arg)
7170
{
72-
int error;
7371
static uint8_t reset_control;
7472

7573
if (bytes != 1)
@@ -81,14 +79,12 @@ reset_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
8179

8280
if (*eax & 0x8) {
8381
fprintf(stderr, "full reset\r\n");
84-
error = vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
85-
assert(error ==0 || errno == EALREADY);
82+
vm_suspend(ctx, VM_SUSPEND_FULL_RESET);
8683
mevent_notify();
8784
reset_control = 0;
8885
} else if (*eax & 0x4) {
8986
fprintf(stderr, "system reset\r\n");
90-
error = vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET);
91-
assert(error ==0 || errno == EALREADY);
87+
vm_suspend(ctx, VM_SUSPEND_SYSTEM_RESET);
9288
mevent_notify();
9389
}
9490
}
@@ -279,8 +275,6 @@ static int
279275
pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
280276
uint32_t *eax, void *arg)
281277
{
282-
int error;
283-
284278
if (bytes != 2)
285279
return -1;
286280
if (in)
@@ -300,13 +294,11 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
300294
*/
301295
if (*eax & VIRTUAL_PM1A_SLP_EN) {
302296
if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 5) {
303-
error = vm_suspend(ctx, VM_SUSPEND_POWEROFF);
304-
assert(error == 0 || errno == EALREADY);
297+
vm_suspend(ctx, VM_SUSPEND_POWEROFF);
305298
}
306299

307300
if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 3) {
308-
error = vm_suspend(ctx, VM_SUSPEND_SUSPEND);
309-
assert(error == 0 || errno == EALREADY);
301+
vm_suspend(ctx, VM_SUSPEND_SUSPEND);
310302
}
311303
}
312304
}
@@ -452,8 +444,7 @@ static int
452444
smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes,
453445
uint32_t *eax, void *arg)
454446
{
455-
assert(!in);
456-
if (bytes != 1)
447+
if (in || (bytes != 1))
457448
return -1;
458449

459450
pthread_mutex_lock(&pm_lock);

devicemodel/hw/platform/acpi/acpi.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,13 @@ void
857857
dsdt_indent(int levels)
858858
{
859859
dsdt_indent_level += levels;
860-
assert(dsdt_indent_level >= 0);
861860
}
862861

863862
void
864863
dsdt_unindent(int levels)
865864
{
866-
assert(dsdt_indent_level >= levels);
867-
dsdt_indent_level -= levels;
865+
if (dsdt_indent_level >= levels)
866+
dsdt_indent_level -= levels;
868867
}
869868

870869
void

0 commit comments

Comments
 (0)