]> granicus.if.org Git - mutt/commitdiff
Fix safe_symlink to correctly handle relative paths.
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Jan 1999 09:11:35 +0000 (09:11 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 2 Jan 1999 09:11:35 +0000 (09:11 +0000)
lib.c

diff --git a/lib.c b/lib.c
index a5b0e081cf95d7ecf72e6a026a9a03dd4ba4a3c8..c847450228c3c4ea3fb897695de8ce2a899795c2 100644 (file)
--- 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)
   {