[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] module: Check version before loading a module
Georg Chini
gitlab at gitlab.freedesktop.org
Wed Dec 9 10:56:56 UTC 2020
Georg Chini pushed to branch master at PulseAudio / pulseaudio
Commits:
e43ca00d by Tanu Kaskinen at 2020-12-09T10:34:49+00:00
module: Check version before loading a module
Since there's no stable API for modules, all modules need to be compiled
together with the server. This version check tries to ensure that if
a version mismatch happens, there will be an informative error message
rather than a random crash.
- - - - -
1 changed file:
- src/pulsecore/module.c
Changes:
=====================================
src/pulsecore/module.c
=====================================
@@ -45,6 +45,7 @@
#define PA_SYMBOL_LOAD_ONCE "pa__load_once"
#define PA_SYMBOL_GET_N_USED "pa__get_n_used"
#define PA_SYMBOL_GET_DEPRECATE "pa__get_deprecated"
+#define PA_SYMBOL_GET_VERSION "pa__get_version"
bool pa_module_exists(const char *name) {
const char *paths, *state = NULL;
@@ -113,6 +114,7 @@ void pa_module_hook_connect(pa_module *m, pa_hook *hook, pa_hook_priority_t prio
int pa_module_load(pa_module** module, pa_core *c, const char *name, const char *argument) {
pa_module *m = NULL;
+ const char *(*get_version)(void);
bool (*load_once)(void);
const char* (*get_deprecated)(void);
pa_modinfo *mi;
@@ -147,6 +149,21 @@ int pa_module_load(pa_module** module, pa_core *c, const char *name, const char
goto fail;
}
+ if ((get_version = (const char *(*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_GET_VERSION))) {
+ const char *version = get_version();
+
+ if (!pa_safe_streq(version, PACKAGE_VERSION)) {
+ pa_log("Module \"%s\" version (%s) doesn't match the expected version (%s).",
+ name, pa_strnull(version), PACKAGE_VERSION);
+ errcode = -PA_ERR_IO;
+ goto fail;
+ }
+ } else {
+ pa_log("Symbol \"%s\" not found in module \"%s\".", PA_SYMBOL_GET_VERSION, name);
+ errcode = -PA_ERR_IO;
+ goto fail;
+ }
+
if ((load_once = (bool (*)(void)) pa_load_sym(m->dl, name, PA_SYMBOL_LOAD_ONCE))) {
m->load_once = load_once();
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/e43ca00d5255d81d2004bf33f30dab3843e8aa1d
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/e43ca00d5255d81d2004bf33f30dab3843e8aa1d
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20201209/af6e6a6d/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list