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

Lyndon Brown jnqnfe at gmail.com
Tue Sep 29 00:11:08 CEST 2020


On Mon, 2020-09-28 at 20:38 +0300, Rémi Denis-Courmont wrote:
> Le maanantaina 28. syyskuuta 2020, 20.18.56 EEST Lyndon Brown a écrit
> :
> > 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.
> > 
> > ...
> > 
> >      for (p = vlc_plugins; p != NULL; p = p->next)
> > +    {
> > +        assert((SIZE_MAX - nconf) >= p->conf.count);
> >          nconf += p->conf.count;
> 
> That's not what I'm after. Integer overflow is not physically
> possible there.
> 
> I mean overflowing the allocated buffer because your patch introduces
> a non-
> trivial assumption about sizes.

Right, yes. I did consider this, but took it in the wrong direction for
some reason.

I've replaced patch #2:

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


diff --git a/src/config/core.c b/src/config/core.c
index 5016793074..9f41ff2d4c 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -409,7 +409,7 @@ int config_SortConfig (void)
     if (unlikely(clist == NULL))
         return VLC_ENOMEM;
 
-    nconf = 0;
+    size_t index = 0;
     for (p = vlc_plugins; p != NULL; p = p->next)
     {
         module_config_t *item, *end;
@@ -420,9 +420,11 @@ int config_SortConfig (void)
         {
             if (!CONFIG_ITEM(item->i_type))
                 continue; /* ignore hints */
-            clist[nconf++] = item;
+            assert(index < nconf);
+            clist[index++] = item;
         }
     }
+    assert(index == nconf);
 
     qsort (clist, nconf, sizeof (*clist), confcmp);
 
-------------- 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/4fae86c2/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: core_conf_count_2_v2.patch
Type: text/x-patch
Size: 956 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200928/4fae86c2/attachment-0001.bin>


More information about the vlc-devel mailing list