Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/google/cpu_features.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2021-10-26 16:58:42 +0300
committerGuillaume Chatelet <gchatelet@google.com>2021-10-26 16:58:42 +0300
commit7bd206a75f217da5d53b18f71a44540146a2f1ff (patch)
tree1bee56e8e28bfb7221e223634dc977cda966ad8d
parent55ac9f0556ddcfff1a3a311b756d54e01e9b0938 (diff)
Fix memory overflow
Duplicate of #190
-rw-r--r--src/cpuinfo_x86.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/cpuinfo_x86.c b/src/cpuinfo_x86.c
index ccbe4aa..7c3c6bd 100644
--- a/src/cpuinfo_x86.c
+++ b/src/cpuinfo_x86.c
@@ -1152,7 +1152,9 @@ static void ParseLeaf2(const int max_cpuid_leaf, CacheInfo* info) {
// For newer AMD CPUs uses "CPUID, eax=0x8000001D"
static void ParseCacheInfo(const int max_cpuid_leaf, uint32_t leaf_id,
CacheInfo* info) {
- for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL; cache_id++) {
+ for (int cache_id = 0; cache_id < CPU_FEATURES_MAX_CACHE_LEVEL &&
+ info->size < CPU_FEATURES_MAX_CACHE_LEVEL;
+ cache_id++) {
const Leaf leaf = SafeCpuIdEx(max_cpuid_leaf, leaf_id, cache_id);
CacheType cache_type = ExtractBitRange(leaf.eax, 4, 0);
if (cache_type == CPU_FEATURE_CACHE_NULL) continue;