Skip to content
Snippets Groups Projects
Commit 00e976dc authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov
Browse files

selftests: KVM: Check stat name before other fields

Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2119111



commit ad5b0727
Author: Oliver Upton <oupton@google.com>
Date:   Tue Jul 19 14:31:32 2022 +0000

    selftests: KVM: Check stat name before other fields

    In order to provide more useful test assertions that describe the broken
    stats descriptor, perform sanity check on the stat name before any other
    descriptor field. While at it, avoid dereferencing the name field if the
    sanity check fails as it is more likely to contain garbage.

Signed-off-by: default avatarOliver Upton <oupton@google.com>
Reviewed-by: default avatarAndrew Jones <andrew.jones@linux.dev>
    Message-Id: <20220719143134.3246798-2-oliver.upton@linux.dev>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>

Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
parent 5685ad31
No related branches found
No related tags found
No related merge requests found
......@@ -73,6 +73,10 @@ static void stats_test(int stats_fd)
for (i = 0; i < header.num_desc; ++i) {
pdesc = get_stats_descriptor(stats_desc, i, &header);
/* Check name string */
TEST_ASSERT(strlen(pdesc->name) < header.name_size,
"KVM stats name (index: %d) too long", i);
/* Check type,unit,base boundaries */
TEST_ASSERT((pdesc->flags & KVM_STATS_TYPE_MASK) <= KVM_STATS_TYPE_MAX,
"Unknown KVM stats type");
......@@ -99,9 +103,7 @@ static void stats_test(int stats_fd)
TEST_ASSERT(pdesc->exponent <= 0, "Unsupported KVM stats unit");
break;
}
/* Check name string */
TEST_ASSERT(strlen(pdesc->name) < header.name_size,
"KVM stats name(%s) too long", pdesc->name);
/* Check size field, which should not be zero */
TEST_ASSERT(pdesc->size,
"KVM descriptor(%s) with size of 0", pdesc->name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment