]> granicus.if.org Git - esp-idf/commitdiff
spiffs: check if OBJ_NAME_LEN + OBJ_META_LEN is within limits
authorIvan Grokhotkov <ivan@espressif.com>
Sun, 28 Jan 2018 15:19:43 +0000 (23:19 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 31 Jan 2018 03:14:56 +0000 (11:14 +0800)
The limit was mentioned in spiffs_config.h but was not checked.

Fixes https://github.com/espressif/esp-idf/issues/1546

components/spiffs/Kconfig
components/spiffs/include/spiffs_config.h

index 4eeb18762b789a75cfdae590cf8959e655184f0a..262f0d678b25231c65e8d8e0150af328651835b9 100644 (file)
@@ -76,10 +76,12 @@ config SPIFFS_OBJ_NAME_LEN
     default 32
     range 1 256
     help
-        Object name maximum length. Note that this length 
-        include the zero-termination character, 
-        meaning maximum string of characters can at most be 
-        SPIFFS_OBJ_NAME_LEN - 1.
+        Object name maximum length. Note that this length include the 
+        zero-termination character, meaning maximum string of characters
+        can at most be SPIFFS_OBJ_NAME_LEN - 1.
+        
+        SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed
+        SPIFFS_PAGE_SIZE - 64.
 
 config SPIFFS_USE_MAGIC
     bool "Enable SPIFFS Filesystem Magic"
@@ -108,6 +110,9 @@ config SPIFFS_META_LENGTH
         These bytes can be used in an application-specific manner.
         Set this to at least 4 bytes to enable support for saving file
         modification time.
+        
+        SPIFFS_OBJ_NAME_LEN + SPIFFS_META_LENGTH should not exceed
+        SPIFFS_PAGE_SIZE - 64.
 
 config SPIFFS_USE_MTIME
     bool "Save file modification time"
index 28414facf9f302226a82a064a86f28ffbd833726..a382ba6f9568b2c5ea6b1cf7a3eac87fbad2b34a 100755 (executable)
@@ -153,12 +153,15 @@ extern void spiffs_api_unlock(struct spiffs_t *fs);
 // changes the on-disk format, so the change is not backward-compatible.
 //
 // Do note: the meta length must never exceed
-// logical_page_size - (SPIFFS_OBJ_NAME_LEN + 64)
+// logical_page_size - (SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE)
 //
 // This is derived from following:
 // logical_page_size - (SPIFFS_OBJ_NAME_LEN + sizeof(spiffs_page_header) +
 // spiffs_object_ix_header fields + at least some LUT entries)
 #define SPIFFS_OBJ_META_LEN             (CONFIG_SPIFFS_META_LENGTH)
+#define SPIFFS_PAGE_EXTRA_SIZE          (64)
+_Static_assert(SPIFFS_OBJ_META_LEN + SPIFFS_OBJ_NAME_LEN + SPIFFS_PAGE_EXTRA_SIZE
+        <= CONFIG_SPIFFS_PAGE_SIZE, "SPIFFS_OBJ_META_LEN or SPIFFS_OBJ_NAME_LEN too long");
 
 // Size of buffer allocated on stack used when copying data.
 // Lower value generates more read/writes. No meaning having it bigger