diff options
author | trasz <trasz@FreeBSD.org> | 2015-05-21 13:19:44 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2015-05-21 13:19:44 +0000 |
commit | 609485e24dfcb4457de1f7e13c1462c193c78a95 (patch) | |
tree | 3e274d01323380f659995cbaf9deee27eb3821da | |
parent | eca8c46c2bbe0edd2bbe51ca88762dd06858464f (diff) | |
download | FreeBSD-src-609485e24dfcb4457de1f7e13c1462c193c78a95.zip FreeBSD-src-609485e24dfcb4457de1f7e13c1462c193c78a95.tar.gz |
MFC r279807:
Improve separated_concat() to properly handle the case of concatenating
"/" and "/foo".
-rw-r--r-- | usr.sbin/autofs/common.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c index 8c455c4..0b4adc1 100644 --- a/usr.sbin/autofs/common.c +++ b/usr.sbin/autofs/common.c @@ -136,8 +136,14 @@ separated_concat(const char *s1, const char *s2, char separator) 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); |