diff --git a/realpath.c b/realpath.c index 42acf242d..97b6f461e 100644 --- a/realpath.c +++ b/realpath.c @@ -163,12 +163,19 @@ char * realpath(old, new) errno = ENOTDIR; return(realpath_ret(NULL, cwd)); } + *(temp++) = '\0'; (void) strcpy(buf, temp); + /* if the last '/' is the first char in new we need to preserve it */ + if (new[0] == '\0') { + new[0] = '/'; + new[1] = '\0'; + } + /* - * chdir() to new and go a getcwd() to find real path - * then append buf (last component of the path) and return. + * chdir() to new and go a getcwd() to find real path then + * append buf * (last component of the path) and return. */ if (chdir(new)) return(realpath_ret(NULL, cwd)); diff --git a/sudo_realpath.c b/sudo_realpath.c index 42acf242d..97b6f461e 100644 --- a/sudo_realpath.c +++ b/sudo_realpath.c @@ -163,12 +163,19 @@ char * realpath(old, new) errno = ENOTDIR; return(realpath_ret(NULL, cwd)); } + *(temp++) = '\0'; (void) strcpy(buf, temp); + /* if the last '/' is the first char in new we need to preserve it */ + if (new[0] == '\0') { + new[0] = '/'; + new[1] = '\0'; + } + /* - * chdir() to new and go a getcwd() to find real path - * then append buf (last component of the path) and return. + * chdir() to new and go a getcwd() to find real path then + * append buf * (last component of the path) and return. */ if (chdir(new)) return(realpath_ret(NULL, cwd));