Avoid calling dlerror() multiple times since it clear the error

status after printing the error.
Problem caused by sudo_warn/sudo_fatal being macros...
This commit is contained in:
Todd C. Miller
2015-07-10 10:31:21 -06:00
parent 42666204e2
commit 374146f70f
4 changed files with 16 additions and 6 deletions

View File

@@ -93,7 +93,9 @@ group_plugin_load(char *plugin_info)
/* Open plugin and map in symbol. */ /* Open plugin and map in symbol. */
group_handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); group_handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
if (!group_handle) { 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; goto done;
} }
group_plugin = sudo_dso_findsym(group_handle, "group_plugin"); group_plugin = sudo_dso_findsym(group_handle, "group_plugin");

View File

@@ -60,8 +60,11 @@ main(int argc, char *argv[])
symbols_file = argv[2]; symbols_file = argv[2];
handle = sudo_dso_load(plugin_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); handle = sudo_dso_load(plugin_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
if (handle == NULL) if (handle == NULL) {
sudo_fatalx_nodebug("unable to load %s: %s", plugin_path, sudo_dso_strerror()); 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"); fp = fopen(symbols_file, "r");
if (fp == NULL) if (fp == NULL)
@@ -73,8 +76,9 @@ main(int argc, char *argv[])
*cp = '\0'; *cp = '\0';
sym = sudo_dso_findsym(handle, line); sym = sudo_dso_findsym(handle, line);
if (sym == NULL) { if (sym == NULL) {
const char *errstr = sudo_dso_strerror();
printf("%s: test %d: unable to resolve symbol %s: %s\n", 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++; errors++;
} }
} }

View File

@@ -328,7 +328,9 @@ sudo_sss_open(struct sudo_nss *nss)
/* Load symbols */ /* Load symbols */
handle->ssslib = sudo_dso_load(path, SUDO_DSO_LAZY); handle->ssslib = sudo_dso_load(path, SUDO_DSO_LAZY);
if (handle->ssslib == NULL) { 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?")); sudo_warnx(U_("unable to initialize SSS source. Is SSSD installed on your machine?"));
free(handle); free(handle);
debug_return_int(EFAULT); debug_return_int(EFAULT);

View File

@@ -159,9 +159,11 @@ sudo_load_plugin(struct plugin_container *policy_plugin,
/* Open plugin and map in symbol */ /* Open plugin and map in symbol */
handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL); handle = sudo_dso_load(path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
if (!handle) { if (!handle) {
const char *errstr = sudo_dso_strerror();
sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"), sudo_warnx(U_("error in %s, line %d while loading plugin `%s'"),
_PATH_SUDO_CONF, info->lineno, info->symbol_name); _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; goto bad;
} }
plugin = sudo_dso_findsym(handle, info->symbol_name); plugin = sudo_dso_findsym(handle, info->symbol_name);