From 0315b294973bc3dcb660892b5300f40c8511a418 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 9 Jul 2020 20:39:17 -0700 Subject: [PATCH] liblog: remove faulty logic in __android_logger_valid_buffer_size In testing, I saw that the 'main' and 'events' log buffers were set to incorrect sizes when they were intended to be >= 4MB. The bug is tracked down to an invalid line in __android_logger_valid_buffer_size(): /* maximum memory impact a somewhat arbitrary ~3% */ pages = (pages + 31) / 32; There are two issues with this line: 1) That is not the right calculation for 3%. 2) `pages` is a static variable, so it repeatedly is decremented until reaching 1. The consequence is that this function gives invalid results for the first few calls, then returns true as long as the input is between LOG_BUFFER_MIN_SIZE and LOG_BUFFER_MAX_SIZE. That check is enough, so the rest of this logic is removed. Test: buffers are set to the right sizes. Change-Id: I4d19b1d0fdbd83843d2d61a484ac083d571ef37b --- liblog/properties.cpp | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/liblog/properties.cpp b/liblog/properties.cpp index f5e060c1f..239211273 100644 --- a/liblog/properties.cpp +++ b/liblog/properties.cpp @@ -474,36 +474,7 @@ bool __android_logger_property_get_bool(const char* key, int flag) { } bool __android_logger_valid_buffer_size(unsigned long value) { - static long pages, pagesize; - unsigned long maximum; - - if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) { - return false; - } - - if (!pages) { - pages = sysconf(_SC_PHYS_PAGES); - } - if (pages < 1) { - return true; - } - - if (!pagesize) { - pagesize = sysconf(_SC_PAGESIZE); - if (pagesize <= 1) { - pagesize = PAGE_SIZE; - } - } - - /* maximum memory impact a somewhat arbitrary ~3% */ - pages = (pages + 31) / 32; - maximum = pages * pagesize; - - if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) { - return true; - } - - return value <= maximum; + return LOG_BUFFER_MIN_SIZE <= value && value <= LOG_BUFFER_MAX_SIZE; } struct cache2_property_size {