]> jfr.im git - irc/irssi/irssi.git/commitdiff
module check irssi version
authorailin-nemui <redacted>
Mon, 23 Nov 2015 23:08:20 +0000 (00:08 +0100)
committerailin-nemui <redacted>
Wed, 9 Dec 2015 23:52:33 +0000 (00:52 +0100)
Add explicit checks into every module to match the ABI version defined
in common.h

src/common.h
src/core/expandos.c
src/core/modules-load.c
src/core/modules.h
src/fe-common/core/fe-modules.c
src/fe-common/core/module-formats.c
src/fe-common/core/module-formats.h
src/irc/proxy/proxy.c
src/perl/perl-core.c
src/perl/perl-fe.c

index 0cf951b3341d63f6263dd45d0e0fe80199bd4d38..966e28d0631ce0c6d1eb81920abbbb6e83bd5240 100644 (file)
@@ -6,6 +6,8 @@
 #define IRSSI_GLOBAL_CONFIG "irssi.conf" /* config file name in /etc/ */
 #define IRSSI_HOME_CONFIG "config" /* config file name in ~/.irssi/ */
 
+#define IRSSI_ABI_VERSION 1
+
 #define DEFAULT_SERVER_ADD_PORT 6667
 
 #ifdef HAVE_CONFIG_H
index 1fc517afc98975f1d43d58cfbd6ea63fd2520db5..67aea837924e259d153ea2a5d5dcce61b297e389 100644 (file)
@@ -414,6 +414,13 @@ static char *expando_releasetime(SERVER_REC *server, void *item, int *free_ret)
        return g_strdup_printf("%04d", IRSSI_VERSION_TIME);
 }
 
+/* client abi */
+static char *expando_abiversion(SERVER_REC *server, void *item, int *free_ret)
+{
+        *free_ret = TRUE;
+       return g_strdup_printf("%d", IRSSI_ABI_VERSION);
+}
+
 /* current working directory */
 static char *expando_workdir(SERVER_REC *server, void *item, int *free_ret)
 {
@@ -658,6 +665,8 @@ void expandos_init(void)
                       "", EXPANDO_NEVER, NULL);
        expando_create("versiontime", expando_releasetime,
                       "", EXPANDO_NEVER, NULL);
+       expando_create("abiversion", expando_abiversion,
+                      "", EXPANDO_NEVER, NULL);
        expando_create("W", expando_workdir, NULL);
        expando_create("Y", expando_realname,
                       "window changed", EXPANDO_ARG_NONE,
index 6086d9aec5750b596b7a685643bed8d6acae7741..9baac1d73aa041a7ca806c223c5964890b555af4 100644 (file)
@@ -160,11 +160,14 @@ static int module_load_name(const char *path, const char *rootmodule,
 {
        void (*module_init) (void);
        void (*module_deinit) (void);
+       void (*module_version) (int *);
        GModule *gmodule;
         MODULE_REC *module;
        MODULE_FILE_REC *rec;
+       gpointer value_version = NULL;
        gpointer value1, value2 = NULL;
-       char *initfunc, *deinitfunc;
+       char *versionfunc, *initfunc, *deinitfunc;
+       int module_abi_version = 0;
         int found;
 
        gmodule = module_open(path, &found);
@@ -176,6 +179,27 @@ static int module_load_name(const char *path, const char *rootmodule,
                return found ? 0 : -1;
        }
 
+       /* get the module's irssi abi version 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_version(&module_abi_version);
+       if (module_abi_version != IRSSI_ABI_VERSION) {
+               char *module_abi_versionstr = g_strdup_printf("%d", module_abi_version);
+               module_error(MODULE_ERROR_VERSION_MISMATCH, module_abi_versionstr,
+                            rootmodule, submodule);
+               g_free(module_abi_versionstr);
+               g_module_close(gmodule);
+               return 0;
+       }
+
        /* get the module's init() and deinit() functions */
        initfunc = module_get_func(rootmodule, submodule, "init");
        deinitfunc = module_get_func(rootmodule, submodule, "deinit");
index 75a77c7752dc74d649c4a25d74155d3ad42c7872..b2fa2fa444ea9a89d9d8c6a234f2f52bcbd9ccd2 100644 (file)
@@ -27,6 +27,7 @@
 enum {
        MODULE_ERROR_ALREADY_LOADED,
        MODULE_ERROR_LOAD,
+       MODULE_ERROR_VERSION_MISMATCH,
        MODULE_ERROR_INVALID
 };
 
index df97ceb19a4611bfda7332001fcc78a4b13abdd2..27b6b4c1a4295eac0e3f2042ed38eaa17d78a576 100644 (file)
@@ -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);
index 4ae269505baae73e32c576d26fc65daa87be0dcc..e6d32b6dffe766a52df81824f7b6d9cb5a2868c8 100644 (file)
@@ -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 ABI version $2 but Irssi is version $abiversion, 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 } },
index 18bf91f5177f99837328d932b88206b1c7c472b1..3f06bb97071384629c8f695545bdd533627fb096 100644 (file)
@@ -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,
index ce79e2b7f17e4881ecfc57ae7854bcb5f4f7f163..50a41b21cce00210fb6012993896eb5285b852b0 100644 (file)
@@ -108,3 +108,8 @@ void irc_proxy_deinit(void)
 {
        proxy_listen_deinit();
 }
+
+void irc_proxy_abicheck(int *version)
+{
+       *version = IRSSI_ABI_VERSION;
+}
index 793f9375f193ec3300432429da10af4339404d8c..2f28c718cfe8acfc5a054251a722dfd01e505698 100644 (file)
@@ -466,3 +466,8 @@ void perl_core_deinit(void)
        signal_remove("script error", (SIGNAL_FUNC) sig_script_error);
        PERL_SYS_TERM();
 }
+
+void perl_core_abicheck(int *version)
+{
+       *version = IRSSI_ABI_VERSION;
+}
index 2abc75c00937e44dcfab5978a9e1eaa330e65dba..04305b632773d36112f66529a4be78496e8c8b65 100644 (file)
@@ -278,3 +278,8 @@ void fe_perl_deinit(void)
 
         perl_core_print_script_error(TRUE);
 }
+
+void fe_perl_abicheck(int *version)
+{
+       *version = IRSSI_ABI_VERSION;
+}