From 6961790085f1736b67da933ed0eeac807919cced Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Mon, 17 Oct 2022 09:54:19 +0200 Subject: [PATCH] Utils: Fix theoretical use-after-free Change-Id: I909f2dcd71c2286036f43fce6fc8aa61c55a6695 Reviewed-by: Eike Ziller --- src/libs/utils/fsengine/filepathinfocache.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/fsengine/filepathinfocache.h b/src/libs/utils/fsengine/filepathinfocache.h index 8b88234e3dc..5a5f2be52b9 100644 --- a/src/libs/utils/fsengine/filepathinfocache.h +++ b/src/libs/utils/fsengine/filepathinfocache.h @@ -40,7 +40,13 @@ public: if (!data) { data = new CachedData; *data = retrievalFunction(filePath); - m_cache.insert(filePath, data); + if (Q_UNLIKELY(!m_cache.insert(filePath, data))) { + // This path will never happen, but to silence coverity we + // have to check it since insert in theory could delete + // the object if a cost bigger than the cache size is + // specified. + return {}; + } } // Return a copy of the data, so it cannot be deleted by the cache