From ea4a4f0691a4abc43a4e8f891eb1ef6ecfb7bb5e Mon Sep 17 00:00:00 2001 From: Carter Li Date: Mon, 16 Mar 2026 09:52:43 +0800 Subject: [PATCH] CPUCache (Linux): makes shared cache dedupe key boundary-safe Fixes #2228 --- src/detection/cpucache/cpucache_linux.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/detection/cpucache/cpucache_linux.c b/src/detection/cpucache/cpucache_linux.c index bf15b1586..975a742e8 100644 --- a/src/detection/cpucache/cpucache_linux.c +++ b/src/detection/cpucache/cpucache_linux.c @@ -44,12 +44,15 @@ static const char* parseCpuCacheIndex(FFstrbuf* path, FFCPUCacheResult* result, ffStrbufSubstrBefore(path, baseLen); ffStrbufAppendS(path, "/shared_cpu_list"); - if (!ffReadFileBuffer(path->chars, buffer)) - return "ffReadFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/shared_cpu_list\") == NULL"; + ffStrbufClear(buffer); + ffStrbufAppendC(buffer, '['); + if (!ffAppendFileBuffer(path->chars, buffer)) + return "ffAppendFileBuffer(\"/sys/devices/system/cpu/cpuX/cache/indexX/shared_cpu_list\") == NULL"; ffStrbufTrimRightSpace(buffer); // deduplicate shared caches - ffStrbufAppendF(buffer, "_%u_%u_%u_%u\n", level, sizeKb, lineSize, cacheType); + ffStrbufAppendF(buffer, "_%u_%u_%u_%u]", level, sizeKb, lineSize, cacheType); + if (ffStrbufContain(added, buffer)) return NULL; ffStrbufAppend(added, buffer); ffCPUCacheAddItem(result, level, sizeKb * 1024, lineSize, cacheType);