From d8013e48bb43d8c78eba98b2fae3bc6f6cb90984 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Jun 1994 23:21:23 +0000 Subject: [PATCH] fix bug where /dirname would return NULL --- realpath.c | 11 +++++++++-- sudo_realpath.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) 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));