From: Todd C. Miller Date: Fri, 9 Nov 2012 21:32:29 +0000 (-0500) Subject: Avoid strerror() when possible and just rely on warning/error X-Git-Tag: SUDO_1_8_7~1^2~343 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=56de023de811952d1e2f2512e171ea6c7db0b51e;p=sudo Avoid strerror() when possible and just rely on warning/error to handle errno in the proper locale. --- diff --git a/plugins/sudoers/find_path.c b/plugins/sudoers/find_path.c index 208b88e40..ff1bd096d 100644 --- a/plugins/sudoers/find_path.c +++ b/plugins/sudoers/find_path.c @@ -65,8 +65,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path, int len; /* length parameter */ debug_decl(find_path, SUDO_DEBUG_UTIL) - if (strlen(infile) >= PATH_MAX) - errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG)); + if (strlen(infile) >= PATH_MAX) { + errno = ENAMETOOLONG; + error(1, "%s", infile); + } /* * If we were given a fully qualified or relative path @@ -104,8 +106,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path, * Resolve the path and exit the loop if found. */ len = snprintf(command, sizeof(command), "%s/%s", path, infile); - if (len <= 0 || len >= sizeof(command)) - errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG)); + if (len <= 0 || len >= sizeof(command)) { + errno = ENAMETOOLONG; + error(1, "%s", infile); + } if ((found = sudo_goodpath(command, sbp))) break; @@ -119,8 +123,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path, */ if (!found && checkdot) { len = snprintf(command, sizeof(command), "./%s", infile); - if (len <= 0 || len >= sizeof(command)) - errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG)); + if (len <= 0 || len >= sizeof(command)) { + errno = ENAMETOOLONG; + error(1, "%s", infile); + } found = sudo_goodpath(command, sbp); if (found && ignore_dot) debug_return_int(NOT_FOUND_DOT); diff --git a/plugins/sudoers/group_plugin.c b/plugins/sudoers/group_plugin.c index 660832c22..53f18b24b 100644 --- a/plugins/sudoers/group_plugin.c +++ b/plugins/sudoers/group_plugin.c @@ -88,9 +88,9 @@ group_plugin_load(char *plugin_info) (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info); } if (len <= 0 || len >= sizeof(path)) { - warningx(N_("%s%s: %s"), - (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info, - strerror(ENAMETOOLONG)); + errno = ENAMETOOLONG; + warning("%s%s", + (*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info); goto done; } diff --git a/plugins/sudoers/iolog.c b/plugins/sudoers/iolog.c index bd526caa5..f88b7c204 100644 --- a/plugins/sudoers/iolog.c +++ b/plugins/sudoers/iolog.c @@ -121,7 +121,8 @@ mkdir_parents(char *path) if (mkdir(path, S_IRWXU) != 0) log_fatal(USE_ERRNO, N_("unable to mkdir %s"), path); } else if (!S_ISDIR(sb.st_mode)) { - log_fatal(0, N_("%s: %s"), path, strerror(ENOTDIR)); + errno = ENOTDIR; + log_fatal(USE_ERRNO, "%s", path); } *slash = '/'; } diff --git a/plugins/sudoers/policy.c b/plugins/sudoers/policy.c index 4ec8bc38f..3f6684cf0 100644 --- a/plugins/sudoers/policy.c +++ b/plugins/sudoers/policy.c @@ -40,6 +40,7 @@ #ifdef HAVE_UNISTD_H # include #endif /* HAVE_UNISTD_H */ +#include #include #include #include @@ -493,8 +494,10 @@ sudoers_policy_close(int exit_status, int error_code) } /* We do not currently log the exit status. */ - if (error_code) - warningx(N_("unable to execute %s: %s"), safe_cmnd, strerror(error_code)); + if (error_code) { + errno = error_code; + warning(N_("unable to execute %s"), safe_cmnd); + } /* Close the session we opened in sudoers_policy_init_session(). */ if (ISSET(sudo_mode, MODE_RUN|MODE_EDIT)) diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index a76f12055..ae85138e7 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -685,8 +685,10 @@ set_cmnd(void) } } } - if (strlen(user_cmnd) >= PATH_MAX) - errorx(1, _("%s: %s"), user_cmnd, strerror(ENAMETOOLONG)); + if (strlen(user_cmnd) >= PATH_MAX) { + errno = ENAMETOOLONG; + error(1, "%s", user_cmnd); + } if ((user_base = strrchr(user_cmnd, '/')) != NULL) user_base++; diff --git a/plugins/sudoers/timestamp.c b/plugins/sudoers/timestamp.c index 84f1f2cef..cd2c8c6f1 100644 --- a/plugins/sudoers/timestamp.c +++ b/plugins/sudoers/timestamp.c @@ -400,8 +400,7 @@ remove_timestamp(bool remove) status = rmdir(timestampdir); if (status == -1 && errno != ENOENT) { log_error(0, - N_("unable to remove %s (%s), will reset to the epoch"), - path, strerror(errno)); + N_("unable to remove %s, will reset to the epoch"), path); remove = false; } }