3535
3636#include "plugin-manager.h"
3737
38+ typedef struct CveToolInstance {
39+ CveCheckTool shared ; /*<Public exposed data */
40+ CvePlugin * pkg_plugin ; /*<Our current plugin */
41+ } CveToolInstance ;
3842
3943static CveCheckTool * self ;
40- static CvePlugin * pkg_plugin ;
44+ static CveToolInstance * self_priv ;
4145
4246static char * srpm_dir = NULL ;
4347
@@ -54,6 +58,7 @@ static inline void package_free(void *p)
5458 return ;
5559 }
5660 struct source_package_t * t = p ;
61+ CvePlugin * pkg_plugin = self_priv -> pkg_plugin ;
5762
5863 if (t -> extra && pkg_plugin && pkg_plugin -> free_package ) {
5964 pkg_plugin -> free_package (t );
@@ -85,6 +90,7 @@ static void cve_add_package_internal(struct source_package_t *pkg)
8590 GList * issues = NULL , * em = NULL ;
8691 gchar * cur_id = NULL ;
8792 gchar * q = NULL ;
93+ CvePlugin * pkg_plugin = self_priv -> pkg_plugin ;
8894
8995 if (!pkg ) {
9096 return ;
@@ -237,6 +243,7 @@ static bool load_faux(const char *path)
237243static void cve_add_package (const char * path )
238244{
239245 struct source_package_t * pkg = NULL ;
246+ CvePlugin * pkg_plugin = self_priv -> pkg_plugin ;
240247
241248 if (pkg_plugin -> scan_package ) {
242249 pkg = pkg_plugin -> scan_package (path );
@@ -406,6 +413,7 @@ static bool cve_locate(const char *path, bool recurse)
406413 bool ret = false;
407414 DIR * dir = NULL ;
408415 struct dirent * ent = NULL ;
416+ CvePlugin * pkg_plugin = self_priv -> pkg_plugin ;
409417
410418 if (!pkg_plugin || !(pkg_plugin -> flags & PLUGIN_TYPE_PACKAGE ) || !pkg_plugin -> is_package ) {
411419 fprintf (stderr , "Abnormal configuration in plugin\n" );
@@ -461,15 +469,20 @@ int main(int argc, char **argv)
461469 autofree (CveDB ) * cve_db = NULL ;
462470 GList * pkg_plugins = NULL ;
463471 int ret = EXIT_FAILURE ;
464- CveCheckTool instance = { 0 };
465- instance .modified = -1 ;
472+ CveToolInstance instance = { 0 };
466473 time_t ti ;
467474 CvePlugin * report = NULL ;
468475 CvePlugin * package = NULL ;
469476 LIBXML_TEST_VERSION
470477 bool quiet , db_locked ;
471478
472- self = & instance ;
479+ /* Public API, shared with Plugins */
480+ self = & instance .shared ;
481+ /* Private API, only for our own operations */
482+ self_priv = & instance ;
483+
484+ self -> modified = -1 ;
485+
473486 context = g_option_context_new (" - cve check tool" );
474487 g_option_context_add_main_entries (context , _entries , NULL );
475488 if (!g_option_context_parse (context , & argc , & argv , & error )) {
@@ -558,8 +571,9 @@ int main(int argc, char **argv)
558571 /* Print a list of 'em */
559572 autofree (gchar ) * list = supported_packages (pkg_plugins );
560573 printf ("Currently supported package types: %s\n" , list );
574+ goto cleanup ;
561575 } else {
562- pkg_plugin = package = cve_plugin_get_by_name (forced_type );
576+ package = cve_plugin_get_by_name (forced_type );
563577 if (!package ) {
564578 fprintf (stderr , "Plugin \'%s\' not found.\n" , forced_type );
565579 goto cleanup ;
@@ -569,6 +583,7 @@ int main(int argc, char **argv)
569583 package = NULL ;
570584 goto cleanup ;
571585 }
586+ self_priv -> pkg_plugin = package ;
572587 }
573588 }
574589
@@ -619,7 +634,10 @@ int main(int argc, char **argv)
619634 }
620635
621636 if (!forced_type ) {
622- pkg_plugin = package = plugin_for_path (pkg_plugins , target -> str , false);
637+ package = plugin_for_path (pkg_plugins , target -> str , false);
638+ if (package ) {
639+ self_priv -> pkg_plugin = package ;
640+ }
623641 }
624642
625643 if (modified_stamp ) {
@@ -628,13 +646,13 @@ int main(int argc, char **argv)
628646 fprintf (stderr , "Invalid date\n" );
629647 goto cleanup ;
630648 }
631- instance . modified = (int64_t )ti ;
649+ self -> modified = (int64_t )ti ;
632650 }
633651
634652 self -> hide_patched = hide_patched ;
635653 self -> show_unaffected = show_unaffected ;
636- instance . db = g_hash_table_new_full (g_str_hash , g_str_equal , NULL , package_free );
637- instance . bdb = NULL ;
654+ self -> db = g_hash_table_new_full (g_str_hash , g_str_equal , NULL , package_free );
655+ self -> bdb = NULL ;
638656
639657 if (is_package_list (target )) {
640658 /* Packages file */
@@ -722,7 +740,7 @@ int main(int argc, char **argv)
722740 free (buf );
723741 goto cleanup ;
724742 }
725- pkg_plugin = package ;
743+ self_priv -> pkg_plugin = package ;
726744 }
727745 cve_locate (path , false);
728746clean :
@@ -739,7 +757,7 @@ int main(int argc, char **argv)
739757 fprintf (stderr , "Unsupported package type\n" );
740758 goto cleanup ;
741759 }
742- pkg_plugin = package ;
760+ self_priv -> pkg_plugin = package ;
743761 if (cve_is_dir (target -> str )) {
744762 cve_locate (target -> str , true);
745763 } else {
@@ -787,8 +805,8 @@ int main(int argc, char **argv)
787805 if (pkg_plugins ) {
788806 g_list_free (pkg_plugins );
789807 }
790- if (instance . db ) {
791- g_hash_table_unref (instance . db );
808+ if (self -> db ) {
809+ g_hash_table_unref (self -> db );
792810 }
793811 if (self -> bdb ) {
794812 g_hash_table_unref (self -> bdb );
0 commit comments