From ee023f97ab799461b49b6a3b94250c76e38f281c Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Wed, 2 May 2018 20:20:38 +0200 Subject: [PATCH] mmap_cache: fool-proofing build_mmap_cache Let's try to handle better the situation when build_mmap_cache is called without mmap_cache/mmap_cache_size being reset prior to the call. Reported by Coverity scan. * mmap_cache.c (build_mmap_cache): Set cache_head to tcp->mmap_cache. Reset tcp->mmap_cache_size to 0. --- mmap_cache.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mmap_cache.c b/mmap_cache.c index 19f88abe..0f249796 100644 --- a/mmap_cache.c +++ b/mmap_cache.c @@ -55,7 +55,7 @@ static void build_mmap_cache(struct tcb *tcp) { FILE *fp; - struct mmap_cache_t *cache_head = NULL; + struct mmap_cache_t *cache_head = tcp->mmap_cache; /* start with a small dynamically-allocated array and then expand it */ size_t cur_array_size = 0; char filename[sizeof("/proc/4294967296/maps")]; @@ -68,6 +68,8 @@ build_mmap_cache(struct tcb *tcp) return; } + tcp->mmap_cache_size = 0; + while (fgets(buffer, sizeof(buffer), fp) != NULL) { struct mmap_cache_t *entry; unsigned long start_addr, end_addr, mmap_offset;