svn commit: r279807 - head/usr.sbin/autofs

Edward Tomasz Napierala trasz at FreeBSD.org
Mon Mar 9 13:01:00 UTC 2015


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


More information about the svn-src-head mailing list