[vlc-commits] cache: recompute items and bool items counters

Rémi Denis-Courmont git at videolan.org
Wed Oct 26 21:56:29 CEST 2016


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Oct 26 22:49:45 2016 +0300| [3ee04f0e0909b2109d0e60e5b96188936c27f693] | committer: Rémi Denis-Courmont

cache: recompute items and bool items counters

Recomputing the values is cheap and ensures that they are correct.
Incorrect values could trigger buffer overflows in the configuration
code.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3ee04f0e0909b2109d0e60e5b96188936c27f693
---

 src/modules/cache.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/modules/cache.c b/src/modules/cache.c
index f12f012..27333c1 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -57,7 +57,7 @@
 #ifdef HAVE_DYNAMIC_PLUGINS
 /* Sub-version number
  * (only used to avoid breakage in dev version when cache structure changes) */
-#define CACHE_SUBVERSION_NUM 25
+#define CACHE_SUBVERSION_NUM 26
 
 /* Cache filename */
 #define CACHE_NAME "plugins.dat"
@@ -249,8 +249,6 @@ static int CacheLoadModuleConfig(module_t *module, block_t *file)
     uint16_t lines;
 
     /* Calculate the structure length */
-    LOAD_IMMEDIATE (module->i_config_items);
-    LOAD_IMMEDIATE (module->i_bool_items);
     LOAD_IMMEDIATE (lines);
 
     /* Allocate memory */
@@ -271,6 +269,18 @@ static int CacheLoadModuleConfig(module_t *module, block_t *file)
     for (size_t i = 0; i < lines; i++)
         if (CacheLoadConfig (module->p_config + i, file))
             return -1;
+
+    for (size_t i = 0; i < lines; i++)
+    {
+        unsigned type = module->p_config[i].i_type;
+        if (CONFIG_ITEM(type))
+        {
+            module->i_config_items++;
+            if (type == CONFIG_ITEM_BOOL)
+                module->i_bool_items++;
+        }
+    }
+
     return 0;
 error:
     return -1; /* FIXME: leaks */
@@ -568,8 +578,6 @@ static int CacheSaveModuleConfig (FILE *file, const module_t *module)
 {
     uint16_t lines = module->confsize;
 
-    SAVE_IMMEDIATE (module->i_config_items);
-    SAVE_IMMEDIATE (module->i_bool_items);
     SAVE_IMMEDIATE (lines);
 
     for (size_t i = 0; i < lines; i++)



More information about the vlc-commits mailing list