From: Todd C. Miller Date: Tue, 21 Mar 2017 16:15:31 +0000 (-0600) Subject: Restore the '/' in the path before returning if we encounter an error. X-Git-Tag: SUDO_1_8_20^2~70 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cfb15106e34ff990a97fca3c9bfb08cc3938abc5;p=sudo Restore the '/' in the path before returning if we encounter an error. --- diff --git a/plugins/sudoers/mkdir_parents.c b/plugins/sudoers/mkdir_parents.c index c915eae71..40d888191 100644 --- a/plugins/sudoers/mkdir_parents.c +++ b/plugins/sudoers/mkdir_parents.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009-2016 Todd C. Miller + * Copyright (c) 2009-2017 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -35,6 +35,7 @@ /* * Create any parent directories needed by path (but not path itself). + * Note that path is modified but is restored before it returns. */ bool sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet) @@ -42,7 +43,6 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet) struct stat sb; gid_t parent_gid = 0; char *slash = path; - bool ret = true; debug_decl(sudo_mkdir_parents, SUDOERS_DEBUG_UTIL) /* If no gid specified, inherit from parent dir. */ @@ -63,22 +63,19 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet) if (errno != EEXIST) { if (!quiet) sudo_warn(U_("unable to mkdir %s"), path); - ret = false; - break; + goto bad; } /* Already exists, make sure it is a directory. */ if (stat(path, &sb) != 0) { if (!quiet) sudo_warn(U_("unable to stat %s"), path); - ret = false; - break; + goto bad; } if (!S_ISDIR(sb.st_mode)) { if (!quiet) sudo_warnx(U_("%s exists but is not a directory (0%o)"), path, (unsigned int) sb.st_mode); - ret = false; - break; + goto bad; } /* Inherit gid of parent dir for ownership. */ if (*gidp == (gid_t)-1) @@ -88,7 +85,11 @@ sudo_mkdir_parents(char *path, uid_t uid, gid_t *gidp, mode_t mode, bool quiet) } /* Return parent gid if none was specified by caller. */ - if (ret && *gidp == (gid_t)-1) + if (*gidp == (gid_t)-1) *gidp = parent_gid; - debug_return_bool(ret); + debug_return_bool(true); +bad: + /* We must restore the path before we return. */ + *slash = '/'; + debug_return_bool(false); }