aboutsummaryrefslogtreecommitdiff
path: root/crypto/openssh/openbsd-compat/realpath.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/openssh/openbsd-compat/realpath.c')
-rw-r--r--crypto/openssh/openbsd-compat/realpath.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/crypto/openssh/openbsd-compat/realpath.c b/crypto/openssh/openbsd-compat/realpath.c
index b9035ca229fb..77da14e7c246 100644
--- a/crypto/openssh/openbsd-compat/realpath.c
+++ b/crypto/openssh/openbsd-compat/realpath.c
@@ -13,6 +13,9 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -32,7 +35,7 @@
#if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH)
#if defined(LIBC_SCCS) && !defined(lint)
-static char *rcsid = "$OpenBSD: realpath.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $";
+static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -62,7 +65,7 @@ char *
realpath(const char *path, char *resolved)
{
struct stat sb;
- int fd, n, rootd, serrno = 0;
+ int fd, n, needslash, serrno = 0;
char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN];
int symlinks = 0;
@@ -138,18 +141,18 @@ loop:
* happens if the last component is empty, or the dirname is root.
*/
if (resolved[0] == '/' && resolved[1] == '\0')
- rootd = 1;
+ needslash = 0;
else
- rootd = 0;
+ needslash = 1;
if (*wbuf) {
- if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
+ if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) {
serrno = ENAMETOOLONG;
goto err1;
}
- if (rootd == 0)
- (void)strcat(resolved, "/");
- (void)strcat(resolved, wbuf);
+ if (needslash == 0)
+ strlcat(resolved, "/", MAXPATHLEN);
+ strlcat(resolved, wbuf, MAXPATHLEN);
}
/* Go back to where we came from. */