KVM: selftests: Add 'malloc' failure check in vcpu_save_state
authorIvan Orlov <ivan.orlov0322@gmail.com>
Wed, 22 Mar 2023 14:45:28 +0000 (18:45 +0400)
committerSean Christopherson <seanjc@google.com>
Fri, 24 Mar 2023 21:21:16 +0000 (14:21 -0700)
There is a 'malloc' call in vcpu_save_state function, which can
be unsuccessful. This patch will add the malloc failure checking
to avoid possible null dereference and give more information
about test fail reasons.

Signed-off-by: Ivan Orlov <ivan.orlov0322@gmail.com>
Link: https://lore.kernel.org/r/20230322144528.704077-1-ivan.orlov0322@gmail.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/lib/x86_64/processor.c

index c09cd151fbe099aadbfd13687b2e834b9c7e2f6d..a12b21a2ef374ce6383c80daef1bbfbfc40c25a7 100644 (file)
@@ -970,6 +970,7 @@ struct kvm_x86_state *vcpu_save_state(struct kvm_vcpu *vcpu)
        vcpu_run_complete_io(vcpu);
 
        state = malloc(sizeof(*state) + msr_list->nmsrs * sizeof(state->msrs.entries[0]));
+       TEST_ASSERT(state, "-ENOMEM when allocating kvm state");
 
        vcpu_events_get(vcpu, &state->events);
        vcpu_mp_state_get(vcpu, &state->mp_state);