Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 9 Mar 2015 13:01:00 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r279807 - head/usr.sbin/autofs
Message-ID:  <201503091301.t29D10Fk002316@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503091301.t29D10Fk002316>