From owner-freebsd-bugs@FreeBSD.ORG Fri Sep 12 12:22:39 2014 Return-Path: Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B816B954 for ; Fri, 12 Sep 2014 12:22:39 +0000 (UTC) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2001:1900:2254:206a::16:76]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 9F09396E for ; Fri, 12 Sep 2014 12:22:39 +0000 (UTC) Received: from bugs.freebsd.org ([127.0.1.118]) by kenobi.freebsd.org (8.14.9/8.14.9) with ESMTP id s8CCMdew043343 for ; Fri, 12 Sep 2014 12:22:39 GMT (envelope-from bugzilla-noreply@freebsd.org) From: bugzilla-noreply@freebsd.org To: freebsd-bugs@FreeBSD.org Subject: [Bug 193584] New: [autofs] problem when resolving maps with partial path matches Date: Fri, 12 Sep 2014 12:22:39 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: 11.0-CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: bz@FreeBSD.org X-Bugzilla-Status: Needs Triage X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: freebsd-bugs@FreeBSD.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Sep 2014 12:22:39 -0000 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=193584 Bug ID: 193584 Summary: [autofs] problem when resolving maps with partial path matches Product: Base System Version: 11.0-CURRENT Hardware: Any OS: Any Status: Needs Triage Severity: Affects Some People Priority: --- Component: bin Assignee: freebsd-bugs@FreeBSD.org Reporter: bz@FreeBSD.org When an indirect map returns: ... /auto/foo/www /auto/foo/www-bar /auto/foo/www-baz and we are looking up www-bar the strncmp in node_find() will match on www already and try to mount that; if parts of the path are expanded from the key facilitating the & we might try to mount /auto/foo/www-baz from filer:/totally/different/path/& I have tried to figure out how to fix that strncmp without much luck running into other assertion failures due to path being an empty string for the initial map lookup it seemed, so I added some extra comparison to the child loop, which should catch all cases still but handling a possible trailing / makes it look ugly. Trying to avoid a possible strdup() failure, I am using two strlen() and a strncmp() on the longer path; obviously one could also check the lens to be equal first. Here's a part of the diff with all debugging etc. in it still: @@ -674,19 +674,41 @@ node_find(struct node *node, const char *path) struct node *child, *found; char *tmp; - //log_debugx("looking up %s in %s", path, node->n_key); + log_debugx("looking up %s in %s", path, node->n_key); tmp = node_path(node); +#if 1 if (strncmp(tmp, path, strlen(tmp)) != 0) { +#else + log_debugx("comparing '%s' '%s' %zu %zu", tmp, path, strlen(path), strlen(tmp)); + if (strlen(tmp) != 0 && strncmp(tmp, path, strlen(tmp)) != 0) { +#endif free(tmp); return (NULL); } free(tmp); + node_print(node); TAILQ_FOREACH(child, &node->n_children, n_next) { found = node_find(child, path); - if (found != NULL) - return (found); + if (found != NULL) { + size_t pl, tl; + + tmp = node_path(found); + log_debugx("found candidate %s %s %s", tmp, path, found->n_key); + /* node_path() already removes a possible trainling '/'. */ + tl = strlen(tmp); + pl = strlen(path); + if (path[pl-1] == '/') + pl--; + pl = (pl > tl) ? pl : tl; + if (strncmp(tmp, path, pl) == 0) { + log_debugx("found match %s %s %s %zu", tmp, path, found->n_key, pl); + free(tmp); + return (found); + } + free(tmp); + } } return (node); I am sure there is a better, proper solution and I am willing to test. -- You are receiving this mail because: You are the assignee for the bug.