nvram: refuse to open NVRAM for writing if it's too big to be handled
authorRafał Miłecki <zajec5@gmail.com>
Wed, 22 Apr 2015 19:07:19 +0000 (19:07 +0000)
committerRafał Miłecki <zajec5@gmail.com>
Wed, 22 Apr 2015 19:07:19 +0000 (19:07 +0000)
Otherwise writing anything will result in loosing data.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
SVN-Revision: 45565

package/utils/nvram/src/nvram.c

index f2c79ff7ba73062ba5d955ab16e29c4af5aad1d2..0e1c7268375cc7b1d579820118326b63d3e8d272 100644 (file)
@@ -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;