Avoid strerror() when possible and just rely on warning/error
to handle errno in the proper locale.
This commit is contained in:
@@ -65,8 +65,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
|
|||||||
int len; /* length parameter */
|
int len; /* length parameter */
|
||||||
debug_decl(find_path, SUDO_DEBUG_UTIL)
|
debug_decl(find_path, SUDO_DEBUG_UTIL)
|
||||||
|
|
||||||
if (strlen(infile) >= PATH_MAX)
|
if (strlen(infile) >= PATH_MAX) {
|
||||||
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
errno = ENAMETOOLONG;
|
||||||
|
error(1, "%s", infile);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we were given a fully qualified or relative path
|
* 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.
|
* Resolve the path and exit the loop if found.
|
||||||
*/
|
*/
|
||||||
len = snprintf(command, sizeof(command), "%s/%s", path, infile);
|
len = snprintf(command, sizeof(command), "%s/%s", path, infile);
|
||||||
if (len <= 0 || len >= sizeof(command))
|
if (len <= 0 || len >= sizeof(command)) {
|
||||||
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
errno = ENAMETOOLONG;
|
||||||
|
error(1, "%s", infile);
|
||||||
|
}
|
||||||
if ((found = sudo_goodpath(command, sbp)))
|
if ((found = sudo_goodpath(command, sbp)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -119,8 +123,10 @@ find_path(char *infile, char **outfile, struct stat *sbp, char *path,
|
|||||||
*/
|
*/
|
||||||
if (!found && checkdot) {
|
if (!found && checkdot) {
|
||||||
len = snprintf(command, sizeof(command), "./%s", infile);
|
len = snprintf(command, sizeof(command), "./%s", infile);
|
||||||
if (len <= 0 || len >= sizeof(command))
|
if (len <= 0 || len >= sizeof(command)) {
|
||||||
errorx(1, _("%s: %s"), infile, strerror(ENAMETOOLONG));
|
errno = ENAMETOOLONG;
|
||||||
|
error(1, "%s", infile);
|
||||||
|
}
|
||||||
found = sudo_goodpath(command, sbp);
|
found = sudo_goodpath(command, sbp);
|
||||||
if (found && ignore_dot)
|
if (found && ignore_dot)
|
||||||
debug_return_int(NOT_FOUND_DOT);
|
debug_return_int(NOT_FOUND_DOT);
|
||||||
|
@@ -88,9 +88,9 @@ group_plugin_load(char *plugin_info)
|
|||||||
(*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
|
(*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
|
||||||
}
|
}
|
||||||
if (len <= 0 || len >= sizeof(path)) {
|
if (len <= 0 || len >= sizeof(path)) {
|
||||||
warningx(N_("%s%s: %s"),
|
errno = ENAMETOOLONG;
|
||||||
(*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info,
|
warning("%s%s",
|
||||||
strerror(ENAMETOOLONG));
|
(*plugin_info != '/') ? _PATH_SUDO_PLUGIN_DIR : "", plugin_info);
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -121,7 +121,8 @@ mkdir_parents(char *path)
|
|||||||
if (mkdir(path, S_IRWXU) != 0)
|
if (mkdir(path, S_IRWXU) != 0)
|
||||||
log_fatal(USE_ERRNO, N_("unable to mkdir %s"), path);
|
log_fatal(USE_ERRNO, N_("unable to mkdir %s"), path);
|
||||||
} else if (!S_ISDIR(sb.st_mode)) {
|
} 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 = '/';
|
*slash = '/';
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@
|
|||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif /* HAVE_UNISTD_H */
|
#endif /* HAVE_UNISTD_H */
|
||||||
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
@@ -493,8 +494,10 @@ sudoers_policy_close(int exit_status, int error_code)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We do not currently log the exit status. */
|
/* We do not currently log the exit status. */
|
||||||
if (error_code)
|
if (error_code) {
|
||||||
warningx(N_("unable to execute %s: %s"), safe_cmnd, strerror(error_code));
|
errno = error_code;
|
||||||
|
warning(N_("unable to execute %s"), safe_cmnd);
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the session we opened in sudoers_policy_init_session(). */
|
/* Close the session we opened in sudoers_policy_init_session(). */
|
||||||
if (ISSET(sudo_mode, MODE_RUN|MODE_EDIT))
|
if (ISSET(sudo_mode, MODE_RUN|MODE_EDIT))
|
||||||
|
@@ -685,8 +685,10 @@ set_cmnd(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strlen(user_cmnd) >= PATH_MAX)
|
if (strlen(user_cmnd) >= PATH_MAX) {
|
||||||
errorx(1, _("%s: %s"), user_cmnd, strerror(ENAMETOOLONG));
|
errno = ENAMETOOLONG;
|
||||||
|
error(1, "%s", user_cmnd);
|
||||||
|
}
|
||||||
|
|
||||||
if ((user_base = strrchr(user_cmnd, '/')) != NULL)
|
if ((user_base = strrchr(user_cmnd, '/')) != NULL)
|
||||||
user_base++;
|
user_base++;
|
||||||
|
@@ -400,8 +400,7 @@ remove_timestamp(bool remove)
|
|||||||
status = rmdir(timestampdir);
|
status = rmdir(timestampdir);
|
||||||
if (status == -1 && errno != ENOENT) {
|
if (status == -1 && errno != ENOENT) {
|
||||||
log_error(0,
|
log_error(0,
|
||||||
N_("unable to remove %s (%s), will reset to the epoch"),
|
N_("unable to remove %s, will reset to the epoch"), path);
|
||||||
path, strerror(errno));
|
|
||||||
remove = false;
|
remove = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user