From 41b471d235b87c7d3bd1e7e91063b3b8fc6dd52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Wed, 22 Apr 2015 19:07:19 +0000 Subject: [PATCH] nvram: refuse to open NVRAM for writing if it's too big to be handled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise writing anything will result in loosing data. Signed-off-by: Rafał Miłecki git-svn-id: svn://svn.openwrt.org/openwrt/trunk@45565 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/utils/nvram/src/nvram.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/utils/nvram/src/nvram.c b/package/utils/nvram/src/nvram.c index f2c79ff7ba..0e1c726837 100644 --- a/package/utils/nvram/src/nvram.c +++ b/package/utils/nvram/src/nvram.c @@ -389,8 +389,8 @@ nvram_handle_t * nvram_open(const char *file, int rdonly) header = nvram_header(h); - if( header->magic == NVRAM_MAGIC ) - { + if (header->magic == NVRAM_MAGIC && + (rdonly || header->len < NVRAM_SPACE)) { _nvram_rehash(h); free(mtd); return h;