From owner-svn-src-head@FreeBSD.ORG Mon Mar 9 13:01:00 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C9E3DB48; Mon, 9 Mar 2015 13:01:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B53763BB; Mon, 9 Mar 2015 13:01:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t29D10Cr002317; Mon, 9 Mar 2015 13:01:00 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t29D10Fk002316; Mon, 9 Mar 2015 13:01:00 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201503091301.t29D10Fk002316@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Mon, 9 Mar 2015 13:01:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279807 - head/usr.sbin/autofs X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Mar 2015 13:01:00 -0000 Author: trasz Date: Mon Mar 9 13:00:59 2015 New Revision: 279807 URL: https://svnweb.freebsd.org/changeset/base/279807 Log: Improve separated_concat() to properly handle the case of concatenating "/" and "/foo". MFC after: 1 month Sponsored by: The FreeBSD Foundation Modified: head/usr.sbin/autofs/common.c Modified: head/usr.sbin/autofs/common.c ============================================================================== --- head/usr.sbin/autofs/common.c Mon Mar 9 11:59:58 2015 (r279806) +++ head/usr.sbin/autofs/common.c Mon Mar 9 13:00:59 2015 (r279807) @@ -136,8 +136,14 @@ separated_concat(const char *s1, const c assert(s1 != NULL); assert(s2 != NULL); - if (s1[0] == '\0' || s2[0] == '\0' || - s1[strlen(s1) - 1] == separator || s2[0] == separator) { + /* + * If s2 starts with separator - skip it; otherwise concatenating + * "/" and "/foo" would end up returning "//foo". + */ + if (s2[0] == separator) + s2++; + + if (s1[0] == '\0' || s2[0] == '\0' || s1[strlen(s1) - 1] == separator) { ret = asprintf(&result, "%s%s", s1, s2); } else { ret = asprintf(&result, "%s%c%s", s1, separator, s2);