Skip to contentSkip to conversation

target/i386: Fix dereferencing before null check

PATCH New Trieu Huynh 1 participant 1 message Mar 12 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/i386: Fix dereferencing before null check

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

---
 target/i386/sev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/i386/sev.c +1 -2
index cddffe0da8..d23694e05b 100644
@@ -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;
Signature · 1 line
2.43.0