svn commit: r283228 - stable/10/usr.sbin/autofs

Edward Tomasz Napierala trasz at FreeBSD.org
Thu May 21 13:19:45 UTC 2015


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);


More information about the svn-src-all mailing list