From 0f01ed0de3810670d452a488f8f55f84b1298a6b Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 24 Nov 2015 00:08:20 +0100 Subject: [PATCH] module check irssi version Add explicit checks into every module to match the Irssi version date. --- src/core/modules-load.c | 31 ++++++++++++++++++++++++++++- src/core/modules.h | 1 + src/fe-common/core/fe-modules.c | 5 +++++ src/fe-common/core/module-formats.c | 1 + src/fe-common/core/module-formats.h | 1 + src/irc/proxy/proxy.c | 6 ++++++ src/perl/perl-core.c | 6 ++++++ src/perl/perl-fe.c | 6 ++++++ 8 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/core/modules-load.c b/src/core/modules-load.c index 6086d9ae..291e6f28 100644 --- a/src/core/modules-load.c +++ b/src/core/modules-load.c @@ -27,6 +27,8 @@ #include "commands.h" #include "misc.h" +#include "irssi-version.h" + #ifdef HAVE_GMODULE /* Returns the module name without path, "lib" prefix or ".so" suffix */ @@ -160,11 +162,14 @@ static int module_load_name(const char *path, const char *rootmodule, { void (*module_init) (void); void (*module_deinit) (void); + char *(*module_version) (void); GModule *gmodule; MODULE_REC *module; MODULE_FILE_REC *rec; + gpointer value_version = NULL; gpointer value1, value2 = NULL; - char *initfunc, *deinitfunc; + char *versionfunc, *initfunc, *deinitfunc; + char *module_versionstr, *irssi_versionstr; int found; gmodule = module_open(path, &found); @@ -176,6 +181,30 @@ static int module_load_name(const char *path, const char *rootmodule, return found ? 0 : -1; } + /* get the module's irssi abi version string and bail out on mismatch */ + versionfunc = module_get_func(rootmodule, submodule, "abicheck"); + if (!g_module_symbol(gmodule, versionfunc, &value_version)) { + g_free(versionfunc); + module_error(MODULE_ERROR_VERSION_MISMATCH, "0", + rootmodule, submodule); + g_module_close(gmodule); + return 0; + } + g_free(versionfunc); + module_version = value_version; + module_versionstr = module_version(); + irssi_versionstr = g_strdup_printf("%d.%d", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); + if (g_strcmp0(module_versionstr, irssi_versionstr) != 0) { + module_error(MODULE_ERROR_VERSION_MISMATCH, module_versionstr, + rootmodule, submodule); + g_free(irssi_versionstr); + g_free(module_versionstr); + g_module_close(gmodule); + return 0; + } + g_free(irssi_versionstr); + g_free(module_versionstr); + /* get the module's init() and deinit() functions */ initfunc = module_get_func(rootmodule, submodule, "init"); deinitfunc = module_get_func(rootmodule, submodule, "deinit"); diff --git a/src/core/modules.h b/src/core/modules.h index 75a77c77..b2fa2fa4 100644 --- a/src/core/modules.h +++ b/src/core/modules.h @@ -27,6 +27,7 @@ enum { MODULE_ERROR_ALREADY_LOADED, MODULE_ERROR_LOAD, + MODULE_ERROR_VERSION_MISMATCH, MODULE_ERROR_INVALID }; diff --git a/src/fe-common/core/fe-modules.c b/src/fe-common/core/fe-modules.c index df97ceb1..0c310fb9 100644 --- a/src/fe-common/core/fe-modules.c +++ b/src/fe-common/core/fe-modules.c @@ -43,6 +43,10 @@ static void sig_module_error(void *number, const char *data, printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_MODULE_LOAD_ERROR, rootmodule, submodule, data); break; + case MODULE_ERROR_VERSION_MISMATCH: + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, + TXT_MODULE_VERSION_MISMATCH, rootmodule, submodule, data); + break; case MODULE_ERROR_INVALID: printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_MODULE_INVALID, rootmodule, submodule); @@ -99,6 +103,7 @@ static int module_list_sub(MODULE_REC *module, int mark_type, return all_dynamic; } + static void cmd_load_list(void) { GSList *tmp; diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 4ae26950..4fc9749a 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -196,6 +196,7 @@ FORMAT_REC fecommon_core_formats[] = { { "module_already_loaded", "Module {hilight $0/$1} already loaded", 2, { 0, 0 } }, { "module_not_loaded", "Module {hilight $0/$1} is not loaded", 2, { 0, 0 } }, { "module_load_error", "Error loading module {hilight $0/$1}: $2", 3, { 0, 0, 0 } }, + { "module_version_mismatch", "{hilight $0/$1} is version $2 but Irssi is version $V.$versiontime, cannot load", 3, { 0, 0, 0 } }, { "module_invalid", "{hilight $0/$1} isn't Irssi module", 2, { 0, 0 } }, { "module_loaded", "Loaded module {hilight $0/$1}", 2, { 0, 0 } }, { "module_unloaded", "Unloaded module {hilight $0/$1}", 2, { 0, 0 } }, diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 18bf91f5..3f06bb97 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -166,6 +166,7 @@ enum { TXT_MODULE_ALREADY_LOADED, TXT_MODULE_NOT_LOADED, TXT_MODULE_LOAD_ERROR, + TXT_MODULE_VERSION_MISMATCH, TXT_MODULE_INVALID, TXT_MODULE_LOADED, TXT_MODULE_UNLOADED, diff --git a/src/irc/proxy/proxy.c b/src/irc/proxy/proxy.c index ce79e2b7..2480fdee 100644 --- a/src/irc/proxy/proxy.c +++ b/src/irc/proxy/proxy.c @@ -22,6 +22,7 @@ #include "signals.h" #include "settings.h" #include "levels.h" +#include "irssi-version.h" #include "fe-common/core/printtext.h" @@ -108,3 +109,8 @@ void irc_proxy_deinit(void) { proxy_listen_deinit(); } + +char *irc_proxy_abicheck(void) +{ + return g_strdup_printf("%d.%d", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); +} diff --git a/src/perl/perl-core.c b/src/perl/perl-core.c index 793f9375..747a6e05 100644 --- a/src/perl/perl-core.c +++ b/src/perl/perl-core.c @@ -26,6 +26,7 @@ #include "signals.h" #include "misc.h" #include "settings.h" +#include "irssi-version.h" #include "perl-core.h" #include "perl-common.h" @@ -466,3 +467,8 @@ void perl_core_deinit(void) signal_remove("script error", (SIGNAL_FUNC) sig_script_error); PERL_SYS_TERM(); } + +char *perl_core_abicheck(void) +{ + return g_strdup_printf("%d.%d", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); +} diff --git a/src/perl/perl-fe.c b/src/perl/perl-fe.c index 2abc75c0..12e772ba 100644 --- a/src/perl/perl-fe.c +++ b/src/perl/perl-fe.c @@ -27,6 +27,7 @@ #include "printtext.h" #include "completion.h" +#include "irssi-version.h" #include "perl-core.h" @@ -278,3 +279,8 @@ void fe_perl_deinit(void) perl_core_print_script_error(TRUE); } + +char *fe_perl_abicheck(void) +{ + return g_strdup_printf("%d.%d", IRSSI_VERSION_DATE, IRSSI_VERSION_TIME); +}