vcpu_get_reg_list() allocates reg_list with calloc() and immediately
dereferences it via reg_list->n without checking for allocation failure,
unlike every other allocation in this file which is guarded by
TEST_ASSERT(). If calloc() returns NULL the test crashes with a NULL
pointer dereference instead of a clean failure message.
Add the missing TEST_ASSERT() check.
Fixes: fd02029a9e01 ("KVM: selftests: Add aarch64 get-reg-list test")
Signed-off-by: Chaithanya Lagisetty <[email protected]>
---
tools/testing/selftests/kvm/lib/kvm_util.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c
b/tools/testing/selftests/kvm/lib/kvm_util.c
index 9ddc047d5c27..d15f39900ed7 100644
--- a/tools/testing/selftests/kvm/lib/kvm_util.c
+++ b/tools/testing/selftests/kvm/lib/kvm_util.c
@@ -1727,6 +1727,7 @@ struct kvm_reg_list *vcpu_get_reg_list(struct kvm_vcpu
*vcpu)
TEST_ASSERT(ret == -1 && errno == E2BIG, "KVM_GET_REG_LIST n=0");
reg_list = calloc(1, sizeof(*reg_list) + reg_list_n.n * sizeof(__u64));
+ TEST_ASSERT(reg_list, "Failed to allocate reg_list");
reg_list->n = reg_list_n.n;
vcpu_ioctl(vcpu, KVM_GET_REG_LIST, reg_list);
return reg_list;
--
2.43.0