Revision: 76767
          http://sourceforge.net/p/brlcad/code/76767
Author:   starseeker
Date:     2020-08-15 00:29:12 +0000 (Sat, 15 Aug 2020)
Log Message:
-----------
Add a version number validation to the libdm plugin loading

Modified Paths:
--------------
    brlcad/branches/RELEASE/include/dm/defines.h
    brlcad/branches/RELEASE/src/libdm/X/dm-X.c
    brlcad/branches/RELEASE/src/libdm/dm_init.cpp
    brlcad/branches/RELEASE/src/libdm/glx/dm-ogl.c
    brlcad/branches/RELEASE/src/libdm/include/calltable.h
    brlcad/branches/RELEASE/src/libdm/osgl/dm-osgl.cpp
    brlcad/branches/RELEASE/src/libdm/plot/dm-plot.c
    brlcad/branches/RELEASE/src/libdm/postscript/CMakeLists.txt
    brlcad/branches/RELEASE/src/libdm/postscript/dm-ps.c
    brlcad/branches/RELEASE/src/libdm/qt/dm-qt.cpp
    brlcad/branches/RELEASE/src/libdm/tk/dm-tk.c
    brlcad/branches/RELEASE/src/libdm/txt/dm-txt.c
    brlcad/branches/RELEASE/src/libdm/wgl/dm-wgl.c

Property Changed:
----------------
    brlcad/branches/RELEASE/

Index: brlcad/branches/RELEASE
===================================================================
--- brlcad/branches/RELEASE     2020-08-15 00:28:25 UTC (rev 76766)
+++ brlcad/branches/RELEASE     2020-08-15 00:29:12 UTC (rev 76767)

Property changes on: brlcad/branches/RELEASE
___________________________________________________________________
Modified: svn:mergeinfo
## -7,4 +7,4 ##
 /brlcad/branches/opencl:65867-66137
 /brlcad/branches/osg:62110-62113
 /brlcad/branches/prep-cache:68236-68933
-/brlcad/trunk:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-75207,75325,75375,75377-75378,75387,75470-75472,75477,75492,75495,75549,75565-75566,75656-75661,75672,75675,75678,75729,75811,76641-76644,76655,76662-76663,76729-76730
\ No newline at end of property
+/brlcad/trunk:36844-37285,37571-38764,38777-38845,41559-43155,43159-43908,44241-44324,44326-44385,44710-45373,45377,45379-47342,47370-68122,68125-75207,75325,75375,75377-75378,75387,75470-75472,75477,75492,75495,75549,75565-75566,75656-75661,75672,75675,75678,75729,75811,76641-76644,76655,76662-76663,76729-76730,76748-76764
\ No newline at end of property
Modified: brlcad/branches/RELEASE/include/dm/defines.h
===================================================================
--- brlcad/branches/RELEASE/include/dm/defines.h        2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/include/dm/defines.h        2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -26,6 +26,8 @@
 #ifndef DM_DEFINES_H
 #define DM_DEFINES_H
 
+#include "common.h"
+
 #ifndef DM_EXPORT
 #  if defined(DM_DLL_EXPORTS) && defined(DM_DLL_IMPORTS)
 #    error "Only DM_DLL_EXPORTS or DM_DLL_IMPORTS can be defined, not both."
@@ -57,6 +59,7 @@
 };
 
 struct dm_plugin {
+    uint32_t api_version;
     const struct dm * const p;
 };
 

Modified: brlcad/branches/RELEASE/src/libdm/X/dm-X.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/X/dm-X.c  2020-08-15 00:28:25 UTC (rev 
76766)
+++ brlcad/branches/RELEASE/src/libdm/X/dm-X.c  2020-08-15 00:29:12 UTC (rev 
76767)
@@ -2150,7 +2150,7 @@
 struct dm dm_X = { &dm_X_impl };
 
 #ifdef DM_PLUGIN
-static const struct dm_plugin pinfo = { &dm_X };
+static const struct dm_plugin pinfo = { DM_API, &dm_X };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/dm_init.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libdm/dm_init.cpp       2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/dm_init.cpp       2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -98,14 +98,30 @@
 
            const struct dm_plugin *plugin = plugin_info();
 
-           if (!plugin || !plugin->p) {
+           if (!plugin) {
                bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from 
'%s' (skipping)\n", pfile);
                bu_dlclose(dl_handle);
                continue;
            }
 
+           if (((uintptr_t)(plugin) & (sizeof((uintptr_t)(plugin))-1)) || 
*((const uint32_t *)(plugin)) != (uint32_t)(DM_API)) {
+               bu_vls_printf(dm_init_msg_str, "Plugin version %d of '%s' 
differs from %d (skipping)\n", *((const uint32_t *)(plugin)), pfile, DM_API);
+               bu_dlclose(dl_handle);
+               continue;
+           }
+
+           if (!plugin->p) {
+               bu_vls_printf(dm_init_msg_str, "Invalid plugin encountered from 
'%s' (skipping)\n", pfile);
+               bu_dlclose(dl_handle);
+               continue;
+           }
+
            const struct dm *d = plugin->p;
            const char *dname = dm_get_name(d);
+           if (!dname) {
+               bu_vls_printf(dm_init_msg_str, "Warning - file '%s' does not 
provide a display manager name (?), skipping\n", pfile);
+               continue;
+           }
            std::string key(dname);
            std::transform(key.begin(), key.end(), key.begin(), [](unsigned 
char c){ return std::tolower(c); });
            if (dm_map.find(key) != dm_map.end()) {

Modified: brlcad/branches/RELEASE/src/libdm/glx/dm-ogl.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/glx/dm-ogl.c      2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/glx/dm-ogl.c      2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -3087,7 +3087,7 @@
 struct dm dm_ogl = { &dm_ogl_impl };
 
 #ifdef DM_PLUGIN
-static const struct dm_plugin pinfo = { &dm_ogl };
+static const struct dm_plugin pinfo = { DM_API, &dm_ogl };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/include/calltable.h
===================================================================
--- brlcad/branches/RELEASE/src/libdm/include/calltable.h       2020-08-15 
00:28:25 UTC (rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/include/calltable.h       2020-08-15 
00:29:12 UTC (rev 76767)
@@ -39,9 +39,12 @@
 #include "bu/parse.h"
 #include "bu/vls.h"
 #include "dm.h"
+#include "brlcad_version.h"
 
 __BEGIN_DECLS
 
+#define DM_API ((BRLCAD_VERSION_MAJOR*10000) + (BRLCAD_VERSION_MINOR*100) + 
BRLCAD_VERSION_PATCH)
+
 struct dm_vars {
     void *pub_vars;
     void *priv_vars;

Modified: brlcad/branches/RELEASE/src/libdm/osgl/dm-osgl.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libdm/osgl/dm-osgl.cpp  2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/osgl/dm-osgl.cpp  2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -2739,7 +2739,7 @@
     struct dm dm_osgl = { &dm_osgl_impl };
 
 #ifdef DM_PLUGIN
-    static const struct dm_plugin pinfo = { &dm_osgl };
+    static const struct dm_plugin pinfo = { DM_API, &dm_osgl };
 
     COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
     {

Modified: brlcad/branches/RELEASE/src/libdm/plot/dm-plot.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/plot/dm-plot.c    2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/plot/dm-plot.c    2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -759,7 +759,7 @@
 struct dm dm_plot = { &dm_plot_impl };
 
 #ifdef DM_PLUGIN
-const struct dm_plugin pinfo = { &dm_plot };
+const struct dm_plugin pinfo = { DM_API, &dm_plot };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/postscript/CMakeLists.txt
===================================================================
--- brlcad/branches/RELEASE/src/libdm/postscript/CMakeLists.txt 2020-08-15 
00:28:25 UTC (rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/postscript/CMakeLists.txt 2020-08-15 
00:29:12 UTC (rev 76767)
@@ -12,7 +12,7 @@
 add_definitions(-DDM_PLUGIN)
 
 add_library(dm-ps SHARED ${PS_SRCS})
-target_link_libraries(dm-ps libdm libbu)
+target_link_libraries(dm-ps libdm libbu ${TCL_LIBRARY})
 set_property(TARGET dm-ps APPEND PROPERTY COMPILE_DEFINITIONS BRLCADBUILD 
HAVE_CONFIG_H)
 VALIDATE_STYLE(dm-ps "${PS_SRCS}")
 

Modified: brlcad/branches/RELEASE/src/libdm/postscript/dm-ps.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/postscript/dm-ps.c        2020-08-15 
00:28:25 UTC (rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/postscript/dm-ps.c        2020-08-15 
00:29:12 UTC (rev 76767)
@@ -829,7 +829,7 @@
 struct dm dm_ps = { &dm_ps_impl };
 
 #ifdef DM_PLUGIN
-const struct dm_plugin pinfo = { &dm_ps };
+const struct dm_plugin pinfo = { DM_API, &dm_ps };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/qt/dm-qt.cpp
===================================================================
--- brlcad/branches/RELEASE/src/libdm/qt/dm-qt.cpp      2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/qt/dm-qt.cpp      2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -1404,7 +1404,7 @@
     struct dm dm_qt = { &dm_qt_impl };
 
 #ifdef DM_PLUGIN
-    static const struct dm_plugin pinfo = { &dm_qt };
+    static const struct dm_plugin pinfo = { DM_API, &dm_qt };
 
     COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
     {

Modified: brlcad/branches/RELEASE/src/libdm/tk/dm-tk.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/tk/dm-tk.c        2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/tk/dm-tk.c        2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -1201,7 +1201,7 @@
 struct dm dm_tk = { &dm_tk_impl };
 
 #ifdef DM_PLUGIN
-static const struct dm_plugin pinfo = { &dm_tk };
+static const struct dm_plugin pinfo = { DM_API, &dm_tk };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/txt/dm-txt.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/txt/dm-txt.c      2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/txt/dm-txt.c      2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -443,7 +443,7 @@
 struct dm dm_txt = { &dm_txt_impl };
 
 #ifdef DM_PLUGIN
-const struct dm_plugin pinfo = { &dm_txt };
+const struct dm_plugin pinfo = { DM_API, &dm_txt };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

Modified: brlcad/branches/RELEASE/src/libdm/wgl/dm-wgl.c
===================================================================
--- brlcad/branches/RELEASE/src/libdm/wgl/dm-wgl.c      2020-08-15 00:28:25 UTC 
(rev 76766)
+++ brlcad/branches/RELEASE/src/libdm/wgl/dm-wgl.c      2020-08-15 00:29:12 UTC 
(rev 76767)
@@ -2660,7 +2660,7 @@
 struct dm dm_wgl = { &dm_wgl_impl };
 
 #ifdef DM_PLUGIN
-static const struct dm_plugin pinfo = { &dm_wgl };
+static const struct dm_plugin pinfo = { DM_API, &dm_wgl };
 
 COMPILER_DLLEXPORT const struct dm_plugin *dm_plugin_info()
 {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to