From: Frank Lahm Date: Wed, 10 Oct 2012 12:42:38 +0000 (+0200) Subject: Avoid excessive path copying when checking for duplicate or nested paths X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=netatalk.git;a=commitdiff_plain;h=1f9ecb322ea2fc83c231102f5d4885277ee71650 Avoid excessive path copying when checking for duplicate or nested paths --- diff --git a/libatalk/util/netatalk_conf.c b/libatalk/util/netatalk_conf.c index 48f60783..4a309485 100644 --- a/libatalk/util/netatalk_conf.c +++ b/libatalk/util/netatalk_conf.c @@ -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(name, vol->v_localname)) { LOG(log_debug, logtype_afpd, "createvol('%s'): already loaded", name); } else { LOG(log_error, logtype_afpd, "paths are duplicated - \"%s\"", path);