[PATCH] target/i386: Fix dereferencing before null check

Trieu Huynh posted 1 patch 3 weeks, 5 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260312123744.232366-1-vikingtc4@gmail.com
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Zhao Liu <zhao1.liu@intel.com>, Marcelo Tosatti <mtosatti@redhat.com>
target/i386/sev.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] target/i386: Fix dereferencing before null check
Posted by Trieu Huynh 3 weeks, 5 days ago
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 <vikingtc4@gmail.com>
---
 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