From a99369903a7c7b4f34b471098768de350fbfef35 Mon Sep 17 00:00:00 2001 From: Balazs Scheidler Date: Tue, 15 Oct 2024 10:12:02 +0200 Subject: [PATCH] cfg-args: fix potential NULL deref in cfg_args_get_as_boolean() Signed-off-by: Balazs Scheidler --- lib/cfg-args.c | 5 ++++- lib/cfg-args.h | 2 +- modules/python/python-plugin.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cfg-args.c b/lib/cfg-args.c index 796e7baeee..c3e6167911 100644 --- a/lib/cfg-args.c +++ b/lib/cfg-args.c @@ -97,10 +97,13 @@ cfg_args_get(CfgArgs *self, const gchar *name) } gboolean -cfg_args_get_as_boolean(CfgArgs *self, const gchar *name) +cfg_args_get_as_boolean(CfgArgs *self, const gchar *name, gboolean default_value) { const gchar *value = cfg_args_get(self, name); + if (!value) + return default_value; + if (strcmp(value, "yes") == 0) return TRUE; else if (strcmp(value, "no") == 0) diff --git a/lib/cfg-args.h b/lib/cfg-args.h index 14883078bf..f6c1d5b16a 100644 --- a/lib/cfg-args.h +++ b/lib/cfg-args.h @@ -33,7 +33,7 @@ typedef struct _CfgArgs CfgArgs; gchar *cfg_args_format_varargs(CfgArgs *self, CfgArgs *defaults); void cfg_args_set(CfgArgs *self, const gchar *name, const gchar *value); const gchar *cfg_args_get(CfgArgs *self, const gchar *name); -gboolean cfg_args_get_as_boolean(CfgArgs *self, const gchar *name); +gboolean cfg_args_get_as_boolean(CfgArgs *self, const gchar *name, gboolean default_value); gboolean cfg_args_contains(CfgArgs *self, const gchar *name); void cfg_args_remove_normalized(CfgArgs *self, const gchar *normalized_name); void cfg_args_remove(CfgArgs *self, const gchar *name); diff --git a/modules/python/python-plugin.c b/modules/python/python-plugin.c index 76db6e555f..bcf5818c1b 100644 --- a/modules/python/python-plugin.c +++ b/modules/python/python-plugin.c @@ -73,7 +73,7 @@ static Plugin python_plugins[] = gboolean python_module_init(PluginContext *context, CfgArgs *args) { - gboolean use_virtualenv = args ? cfg_args_get_as_boolean(args, "use-virtualenv") : TRUE; + gboolean use_virtualenv = args ? cfg_args_get_as_boolean(args, "use-virtualenv", TRUE) : TRUE; if (!_py_init_interpreter(use_virtualenv)) return FALSE; python_debugger_init();