]> arthur.barton.de Git - netatalk.git/commitdiff
Use realpath_safe() for getting the absolute path
authorRalph Boehme <rb@sernet.de>
Tue, 24 Jun 2014 08:44:47 +0000 (10:44 +0200)
committerRalph Boehme <rb@sernet.de>
Tue, 24 Jun 2014 08:44:47 +0000 (10:44 +0200)
Authored-by: gaaronk
Reviewed-by: Ralph Boehme <rb@sernet.de>
libatalk/util/netatalk_conf.c

index 2e1812ddcc0e3cc38aa3f09ec42dbe916421147b..3548164cfc99cad74e7deff1045f4452eaaa3fb0 100644 (file)
@@ -1600,36 +1600,18 @@ struct vol *getvolbypath(AFPObj *obj, const char *path)
     struct vol *tmp;
     const struct passwd *pw;
     char        volname[AFPVOL_U8MNAMELEN + 1];
-    char        abspath[MAXPATHLEN + 1];
+    char        *realabspath = NULL;
     char        volpath[MAXPATHLEN + 1], *realvolpath = NULL;
     char        tmpbuf[MAXPATHLEN + 1];
     const char *secname, *basedir, *p = NULL, *subpath = NULL, *subpathconfig;
     char *user = NULL, *prw;
     regmatch_t match[1];
-    size_t abspath_len;
 
     LOG(log_debug, logtype_afpd, "getvolbypath(\"%s\")", path);
 
-    if (path[0] != '/') {
-        /* relative path, build absolute path */
-        EC_NULL_LOG( getcwd(abspath, MAXPATHLEN) );
-        strlcat(abspath, "/", MAXPATHLEN);
-        strlcat(abspath, path, MAXPATHLEN);
-        path = abspath;
-    } else {
-        strlcpy(abspath, path, MAXPATHLEN);
-        path = abspath;
-    }
-    /* path now points to a copy of path in the abspath buffer */
-
-    /*
-     * Strip trailing slashes
-     */
-    abspath_len = strlen(abspath);
-    while (abspath[abspath_len - 1] == '/') {
-        abspath[abspath_len - 1] = 0;
-        abspath_len--;
-    }
+    /*  build absolute path */
+    EC_NULL( realabspath = realpath_safe(path) );
+    path = realabspath;
 
     for (tmp = Volumes; tmp; tmp = tmp->v_next) { /* (1) */
         size_t v_path_len = strlen(tmp->v_path);
@@ -1751,6 +1733,8 @@ EC_CLEANUP:
         free(user);
     if (realvolpath)
         free(realvolpath);
+    if (realabspath)
+        free(realabspath);
     if (ret != 0)
         vol = NULL;
     return vol;