From: Thomas Roessler Date: Sat, 2 Jan 1999 09:11:35 +0000 (+0000) Subject: Fix safe_symlink to correctly handle relative paths. X-Git-Tag: archive/mutt-0-95-exp~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cde06330343329201736e4279180e969f896a7f2;p=mutt Fix safe_symlink to correctly handle relative paths. --- diff --git a/lib.c b/lib.c index a5b0e081..c8474502 100644 --- a/lib.c +++ b/lib.c @@ -691,9 +691,25 @@ int safe_symlink(const char *oldpath, const char *newpath) if(unlink(newpath) == -1 && errno != ENOENT) return -1; - if(symlink(oldpath, newpath) == -1) + if (oldpath[0] == '/') + { + if (symlink (oldpath, newpath) == -1) + return -1; + } + else + { + char abs_oldpath[_POSIX_PATH_MAX]; + + if ((getcwd (abs_oldpath, sizeof abs_oldpath) == NULL) || + (strlen (abs_oldpath) + 1 + strlen (oldpath) + 1 > sizeof abs_oldpath)) return -1; + strcat (abs_oldpath, "/"); + strcat (abs_oldpath, oldpath); + if (symlink (abs_oldpath, newpath) == -1) + return -1; + } + if(stat(oldpath, &osb) == -1 || stat(newpath, &nsb) == -1 || compare_stat(&osb, &nsb) == -1) {