java-topology/defects/vlc/patch/vlc-0001.patch
russell@unturf.com 9934133dcf whitepaper: 312 sites / 151 ecosystems — wave2+3 defect tables and PDF rebuild
Add 88 new defect entries to HIGH and MEDIUM tables:
  HIGH: mysql-0001/0002, mariadb-0001, redis-0001/0002, valkey-0001/0002, openvpn-0001,
        vlc-0001, prometheus-0001, otel-collector-0001, cockroachdb-0001..0004,
        tidb-0001..0008, kubernetes-0001/0002, go-0001, kotlin-0002, scala-0001,
        allegro5-0001, sdl2-0001, grafana-0001, clickhouse-0001, duckdb-0001,
        mongodb-0001, envoy-0001, istio-0001, cilium-0001, linkerd2-0001,
        linux-0001/0002/0003, tor-0002/0003, curl-0001, julia-0001, lua-0001,
        perl5-0001, nats-0001, spring-0003/0004, tomcat-0001, onos-0002, odl-0002

  MEDIUM: helm-0001, mariadb-0002, openssl-0001/0002, memcached-0001,
          cassandra-0001..0004, flink-0001, storm-0001/0002, zookeeper-0001..0003,
          pip-0001, gradle-0001, nginx-0001, haproxy-0001, caddy-0001, varnish-0001,
          ffmpeg-0001, gstreamer-0001, raylib-0001, love2d-0001, php-0001/0002,
          r-source-0001, cpython-0002, ruby-0001, rabbitmq-0003/0004, activemq-0001,
          ovs-0001, onos-0003, odl-0002, jetty-0001

PDF: 976K
2026-03-27 15:23:43 -04:00

91 lines
2.7 KiB
Diff

--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -50,6 +50,7 @@
#include "modules/modules.h"
#include "config/configuration.h"
+#include <search.h> /* tsearch, tfind, twalk */
+
/**
* Structure of a module bank
*/
@@ -55,6 +56,8 @@ static struct
{
vlc_plugin_t *libs; /**< Loaded plugins */
vlc_modcap_t *caps_tree; /**< Capability-indexed BST */
+ void *name_tree; /**< Name-indexed BST (module_t* by shortcut[0]) */
size_t count; /**< Total module count */
void *caches; /**< Saved cache data */
} modules = { NULL, NULL, 0, NULL };
@@ -109,6 +112,33 @@ static void vlc_modcap_sort(const void *node, const VISIT which,
}
}
+/* Name-indexed BST helpers (CWE-407 fix for module_find) */
+typedef struct vlc_modname {
+ const char *name;
+ module_t *module;
+} vlc_modname_t;
+
+static int vlc_modname_cmp(const void *a, const void *b)
+{
+ const vlc_modname_t *na = a, *nb = b;
+ return strcmp(na->name, nb->name);
+}
+
+/* Called after each module is registered; inserts first shortcut into BST. */
+static void vlc_modname_insert(module_t *m)
+{
+ if (m->i_shortcuts == 0) return;
+ vlc_modname_t *entry = malloc(sizeof(*entry));
+ if (!entry) return;
+ entry->name = m->pp_shortcuts[0];
+ entry->module = m;
+ void **cp = tsearch(entry, &modules.name_tree, vlc_modname_cmp);
+ if (cp == NULL || *cp != entry)
+ free(entry); /* duplicate shortcut or alloc failure */
+}
+
+static void vlc_modname_free(void *data) { free(data); }
+
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -293,15 +293,26 @@ done:
}
+/* CWE-407: module_find() O(N) linear scan replaced with O(1) BST lookup.
+ * The name_tree BST is populated by vlc_modname_insert() during bank load.
+ * Falls back to linear scan only if tree is empty (early-startup edge case).
+ */
module_t *module_find (const char *name)
{
+ /* Fast path: O(log N) BST lookup */
+ extern void *modules_name_tree_get(void); /* forward decl */
+ vlc_modname_t key = { .name = name, .module = NULL };
+ void *tree = modules_name_tree_get();
+ if (tree) {
+ void **cp = tfind(&key, &tree, vlc_modname_cmp);
+ if (cp) return ((vlc_modname_t *)*cp)->module;
+ return NULL;
+ }
+ /* Slow path fallback (tree not yet built) */
size_t count;
module_t **list = module_list_get (&count);
assert (name != NULL);
for (size_t i = 0; i < count; i++)
{
module_t *module = list[i];
if (unlikely(module->i_shortcuts == 0))
continue;
if (!strcmp (module->pp_shortcuts[0], name))
{
module_list_free (list);
return module;
}
}
module_list_free (list);
return NULL;
}