]> granicus.if.org Git - esp-idf/commitdiff
vfs: fix NULL pointer dereference in esp_vfs_unregister
authorIvan Grokhotkov <ivan@espressif.com>
Wed, 21 Jun 2017 05:54:04 +0000 (13:54 +0800)
committerIvan Grokhotkov <ivan@espressif.com>
Wed, 21 Jun 2017 05:54:04 +0000 (13:54 +0800)
components/vfs/test/test_vfs_paths.c
components/vfs/vfs.c

index 033a376db396bf14e0dee63e3ae5d45ae67fe674..c0a863e188cd2e6d6025125c59492f6eacc4196e 100644 (file)
@@ -23,8 +23,6 @@
 #include "unity.h"
 #include "esp_log.h"
 
-static const char* TAG = "test_vfs_paths";
-
 /* Dummy VFS implementation to check if VFS is called or not with expected path
  */
 typedef struct {
@@ -175,4 +173,6 @@ TEST_CASE("vfs parses paths correctly", "[vfs]")
     test_not_called(&inst_foo1, "/foo/file1");
     test_opened(&inst_foo1, "/foo1/file1");
     test_not_opened(&inst_foo1, "/foo1/file");
+    TEST_ESP_OK( esp_vfs_unregister("/foo") );
+    TEST_ESP_OK( esp_vfs_unregister("/foo1") );
 }
index b656cb22b9d640898a3a4d544cc2cbe483ea1496..6501359bb1dd5a048281cfa478c72f27ac943aa9 100644 (file)
@@ -91,6 +91,9 @@ esp_err_t esp_vfs_unregister(const char* base_path)
 {
     for (size_t i = 0; i < s_vfs_count; ++i) {
         vfs_entry_t* vfs = s_vfs[i];
+        if (vfs == NULL) {
+            continue;
+        }
         if (memcmp(base_path, vfs->path_prefix, vfs->path_prefix_len) == 0) {
             free(vfs);
             s_vfs[i] = NULL;