Commit 122e44e7 authored by Alexandros Frantzis's avatar Alexandros Frantzis Committed by Commit Bot

metrics/perf: Fix crash for CPU identities outside CpuUarch table

When running on a system with a CPU family/model beyond the last entry
in the CpuUarch table, the CPU id to CpuUarch mapping code tries to
access an invalid iterator/entry and crashes. Check for this case and
return an empty CpuUarch instead.

Bug: 1021000
Change-Id: I2bc19427a03c0fe6906838bdcb2134021fc213df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1893200Reviewed-by: default avatarGabriel Marin <gmx@chromium.org>
Commit-Queue: Alexandros Frantzis <alexandros.frantzis@collabora.com>
Cr-Commit-Position: refs/heads/master@{#712942}
parent 784a0bcc
......@@ -91,7 +91,8 @@ std::string GetCpuUarch(const CPUIdentity& cpuid) {
auto* bound = std::lower_bound(internal::kCpuUarchTable,
internal::kCpuUarchTableEnd, search_elem,
internal::CpuUarchTableCmp);
if (bound->family_model != family_model)
if (bound == internal::kCpuUarchTableEnd ||
bound->family_model != family_model)
return std::string(); // Unknown uarch
return bound->uarch;
}
......
......@@ -79,6 +79,16 @@ TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_Unknown) {
EXPECT_EQ("", GetCpuUarch(cpuid));
}
TEST(CpuIdentityTest, DefaultCommandsBasedOnArch_UnknownUpperBound) {
CPUIdentity cpuid;
cpuid.arch = "x86_64";
cpuid.vendor = "GenuineIntel";
cpuid.family = 0xff;
cpuid.model = 0xff;
cpuid.model_name = "";
EXPECT_EQ("", GetCpuUarch(cpuid));
}
TEST(CpuIdentityTest, SimplifyCPUModelName) {
EXPECT_EQ("", SimplifyCPUModelName(""));
EXPECT_EQ("intel-celeron-2955u-@-1.40ghz",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment