Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 May 2015 13:19:44 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r283228 - stable/10/usr.sbin/autofs
Message-ID:  <201505211319.t4LDJitP093717@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Thu May 21 13:19:44 2015
New Revision: 283228
URL: https://svnweb.freebsd.org/changeset/base/283228

Log:
  MFC r279807:
  
  Improve separated_concat() to properly handle the case of concatenating
  "/" and "/foo".

Modified:
  stable/10/usr.sbin/autofs/common.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/autofs/common.c
==============================================================================
--- stable/10/usr.sbin/autofs/common.c	Thu May 21 13:18:02 2015	(r283227)
+++ stable/10/usr.sbin/autofs/common.c	Thu May 21 13:19:44 2015	(r283228)
@@ -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?201505211319.t4LDJitP093717>