]> arthur.barton.de Git - netatalk.git/commitdiff
Avoid excessive path copying when checking for duplicate or nested paths
authorFrank Lahm <franklahm@googlemail.com>
Wed, 10 Oct 2012 12:42:38 +0000 (14:42 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Wed, 10 Oct 2012 12:42:38 +0000 (14:42 +0200)
libatalk/util/netatalk_conf.c

index 48f60783ac010c9ab9e83b6d226f9214895e8db9..4a309485b3b270f31dfca01937ea667250fdeb32 100644 (file)
@@ -562,7 +562,6 @@ static struct vol *creatvol(AFPObj *obj,
 {
     EC_INIT;
     struct vol  *volume = NULL;
-    char        current_path[MAXPATHLEN+1], another_path[MAXPATHLEN+1];
     size_t      current_pathlen, another_pathlen;
     int         i, suffixlen, vlen, tmpvlen, u8mvlen, macvlen;
     char        *tmpname;
@@ -586,15 +585,14 @@ static struct vol *creatvol(AFPObj *obj,
     }
 
     /* Once volumes are loaded, we never change options again, we just delete em when they're removed from afp.conf */
-    /* Duplicated or nested volume is ignored  */
-    strlcpy(current_path, path, MAXPATHLEN);
-    current_pathlen = strlcat(current_path, "/", MAXPATHLEN);
+
+    /* Check for duplicated or nested volumes */
+    current_pathlen = strlen(path);
     for (struct vol *vol = Volumes; vol; vol = vol->v_next) {
-        strlcpy(another_path, vol->v_path, MAXPATHLEN);
-        another_pathlen = strlcat(another_path, "/", MAXPATHLEN);
-        if ( 0 == strncmp(current_path, another_path, MIN(current_pathlen, another_pathlen))) {
+        another_pathlen = strlen(vol->v_path);
+        if (strncmp(path, vol->v_path, MIN(current_pathlen, another_pathlen)) == 0) {
             if (current_pathlen == another_pathlen) {
-                if ( 0 == strcmp(name ,vol->v_localname)) {
+                if ( 0 == strcmp(namevol->v_localname)) {
                     LOG(log_debug, logtype_afpd, "createvol('%s'): already loaded", name);
                 } else {
                     LOG(log_error, logtype_afpd, "paths are duplicated - \"%s\"", path);