The 'sev_common' pointer is dereferenced via SEV_COMMON_GET_CLASS() before it is checked for NULL.
Fix this by moving the NULL check to the beginning of the function before any dereferencing occurs. Resolves: CID 1645467 Signed-off-by: Trieu Huynh <[email protected]> --- target/i386/sev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/target/i386/sev.c b/target/i386/sev.c index cddffe0da8..d23694e05b 100644 --- a/target/i386/sev.c +++ b/target/i386/sev.c @@ -2009,11 +2009,10 @@ static int sev_snp_kvm_init(ConfidentialGuestSupport *cgs, Error **errp) static void sev_handle_reset(Object *obj, ResetType type) { SevCommonState *sev_common = SEV_COMMON(MACHINE(qdev_get_machine())->cgs); - SevCommonStateClass *klass = SEV_COMMON_GET_CLASS(sev_common); - if (!sev_common) { return; } + SevCommonStateClass *klass = SEV_COMMON_GET_CLASS(sev_common); if (!runstate_is_running()) { return; -- 2.43.0
