Skip to content

Commit 5d85579

Browse files
rdementiCopilot
andauthored
check l3CacheMaskShift valid ranges
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent c8d6cd5 commit 5d85579

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/cpucounters.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,15 @@ bool PCM::discoverSystemTopology()
12171217
{
12181218
fillEntry(entry, smtMaskWidth, coreMaskWidth, l2CacheMaskShift, getAPICID(0xb));
12191219
}
1220+
// Validate l3CacheMaskShift and ensure the bit range is correct
1221+
if (l3CacheMaskShift < 0 || l3CacheMaskShift > 31)
1222+
{
1223+
throw std::runtime_error("Invalid l3CacheMaskShift: must be between 0 and 31");
1224+
}
1225+
if (l3CacheMaskShift > 31)
1226+
{
1227+
throw std::runtime_error("Invalid bit range for L3 cache ID extraction");
1228+
}
12201229
entry.l3_cache_id = extract_bits_32(getAPICID(0xb), l3CacheMaskShift, 31);
12211230
};
12221231
#endif

0 commit comments

Comments
 (0)