security: add missing NULL check after strdup in context factory registry

Memory Safety: Medium

In pw_context_set_spa_libs(), strdup(lib) was not checked for failure.
A NULL entry->lib would cause a NULL dereference when the factory
library path is later looked up and used for dlopen().

Fix by checking the strdup() return value and cleaning up the regex
and array entry on failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Wim Taymans 2026-04-28 13:20:13 +02:00
parent 640af6b20f
commit 43931caccb

View file

@ -1030,6 +1030,11 @@ int pw_context_add_spa_lib(struct pw_context *context,
}
entry->lib = strdup(lib);
if (entry->lib == NULL) {
regfree(&entry->regex);
pw_array_remove(&context->factory_lib, entry);
return -ENOMEM;
}
pw_log_debug("%p: map factory regex '%s' to '%s", context,
factory_regexp, lib);
return 0;