From 374146f70f0a2aa574dce016d2ed9d9cca8cc70e Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 10 Jul 2015 10:31:21 -0600 Subject: [PATCH] Avoid calling dlerror() multiple times since it clear the error status after printing the error. Problem caused by sudo_warn/sudo_fatal being macros... --- plugins/sudoers/group_plugin.c | 4 +++- plugins/sudoers/regress/check_symbols/check_symbols.c | 10 +++++++--- plugins/sudoers/sssd.c | 4 +++- src/load_plugins.c | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/plugins/sudoers/group_plugin.c b/plugins/sudoers/group_plugin.c index 467eaa4cd..bbd7d5c29 100644 --- a/plugins/sudoers/group_plugin.c +++ b/plugins/sudoers/group_plugin.c @@ -93,7 +93,9 @@ group_plugin_load(char *plugin_info) /* Open plugin and map in symbol. */ group_handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); if (!group_handle) { - sudo_warnx(U_("unable to load %s: %s"), path, sudo_dso_strerror()); + const char *errstr = sudo_dso_strerror(); + sudo_warnx(U_("unable to load %s: %s"), path, + errstr ? errstr : "unknown error"); goto done; } group_plugin = sudo_dso_findsym(group_handle, "group_plugin"); diff --git a/plugins/sudoers/regress/check_symbols/check_symbols.c b/plugins/sudoers/regress/check_symbols/check_symbols.c index 6d104abf5..4ba058379 100644 --- a/plugins/sudoers/regress/check_symbols/check_symbols.c +++ b/plugins/sudoers/regress/check_symbols/check_symbols.c @@ -60,8 +60,11 @@ main(int argc, char *argv[]) symbols_file = argv[2]; handle = sudo_dso_load(plugin_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); - if (handle == NULL) - sudo_fatalx_nodebug("unable to load %s: %s", plugin_path, sudo_dso_strerror()); + if (handle == NULL) { + const char *errstr = sudo_dso_strerror(); + sudo_fatalx_nodebug("unable to load %s: %s", plugin_path, + errstr ? errstr : "unknown error"); + } fp = fopen(symbols_file, "r"); if (fp == NULL) @@ -73,8 +76,9 @@ main(int argc, char *argv[]) *cp = '\0'; sym = sudo_dso_findsym(handle, line); if (sym == NULL) { + const char *errstr = sudo_dso_strerror(); printf("%s: test %d: unable to resolve symbol %s: %s\n", - getprogname(), ntests, line, sudo_dso_strerror()); + getprogname(), ntests, line, errstr ? errstr : "unknown error"); errors++; } } diff --git a/plugins/sudoers/sssd.c b/plugins/sudoers/sssd.c index 7e6f4fc50..7da05b198 100644 --- a/plugins/sudoers/sssd.c +++ b/plugins/sudoers/sssd.c @@ -328,7 +328,9 @@ sudo_sss_open(struct sudo_nss *nss) /* Load symbols */ handle->ssslib = sudo_dso_load(path, SUDO_DSO_LAZY); if (handle->ssslib == NULL) { - sudo_warnx(U_("unable to load %s: %s"), path, sudo_dso_strerror()); + const char *errstr = sudo_dso_strerror(); + sudo_warnx(U_("unable to load %s: %s"), path, + errstr ? errstr : "unknown error"); sudo_warnx(U_("unable to initialize SSS source. Is SSSD installed on your machine?")); free(handle); debug_return_int(EFAULT); diff --git a/src/load_plugins.c b/src/load_plugins.c index d26a2b0cf..3e7d4700e 100644 --- a/src/load_plugins.c +++ b/src/load_plugins.c @@ -159,9 +159,11 @@ sudo_load_plugin(struct plugin_container *policy_plugin, /* Open plugin and map in symbol */ handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); if (!handle) { + const char *errstr = sudo_dso_strerror(); sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"), _PATH_SUDO_CONF, info->lineno, info->symbol_name); - sudo_warnx(U_("unable to load %s: %s"), path, sudo_dso_strerror()); + sudo_warnx(U_("unable to load %s: %s"), path, + errstr ? errstr : "unknown error"); goto bad; } plugin = sudo_dso_findsym(handle, info->symbol_name); -- 2.40.0