Skip to content

Commit

Permalink
cfg-args: fix potential NULL deref in cfg_args_get_as_boolean()
Browse files Browse the repository at this point in the history
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
  • Loading branch information
bazsi committed Oct 20, 2024
1 parent 3add5e7 commit 592bd98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/cfg-args.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/cfg-args.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion modules/python/python-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 592bd98

Please sign in to comment.