[vlc-devel] [PATCH] core: use config count not size

Lyndon Brown jnqnfe at gmail.com
Mon Sep 28 19:18:56 CEST 2020


On Mon, 2020-09-28 at 18:24 +0300, RĂ©mi Denis-Courmont wrote:
> OK but IMO this deserves an assertion in the loop that we don't
> overflow.

Agreed.

I felt it best to do so in it's own commit. I also revised the other
patch to fix the indentation which I noticed was off when adding the
assertion. Both are attached.

Preview of the second patch:

From: Lyndon Brown <jnqnfe at gmail.com>
Date: Mon, 28 Sep 2020 18:01:37 +0100
Subject: core: an assert for overflow in config_SortConfig


diff --git a/src/config/core.c b/src/config/core.c
index 5016793074..c55096332d 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -33,6 +33,7 @@
 
 #include <errno.h>
 #include <assert.h>
+#include <limits.h>
 
 #include "configuration.h"
 #include "modules/modules.h"
@@ -403,7 +404,10 @@ int config_SortConfig (void)
     size_t nconf = 0;
 
     for (p = vlc_plugins; p != NULL; p = p->next)
+    {
+        assert((SIZE_MAX - nconf) >= p->conf.count);
         nconf += p->conf.count;
+    }
 
     module_config_t **clist = vlc_alloc (nconf, sizeof (*clist));
     if (unlikely(clist == NULL))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: core_conf_count_1.patch
Type: text/x-patch
Size: 1054 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200928/5ee041e3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: core_conf_count_2.patch
Type: text/x-patch
Size: 815 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200928/5ee041e3/attachment-0001.bin>


More information about the vlc-devel mailing list