From 3495e82eba80e7569807ce5b637cc88e44e04f02 Mon Sep 17 00:00:00 2001 From: brad <> Date: Sun, 3 Aug 2003 02:29:29 +0000 Subject: [PATCH] MFC: Fix by millert@ Rename rootd to needslash and invert its value. This fixes the check for ENAMETOOLONG, though since we use strlcpy() and strlcat() this is not a big deal. Problem found by vincent@ ok deraadt@ --- src/lib/libc/stdlib/realpath.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index d01b19e0..f9a36e42 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c @@ -35,7 +35,7 @@ */ #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.7.2.1 2003/08/03 02:29:29 brad Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -60,7 +60,7 @@ realpath(path, resolved) char *resolved; { struct stat sb; - int fd, n, rootd, serrno; + int fd, n, needslash, serrno; char *p, *q, wbuf[MAXPATHLEN]; int symlinks = 0; @@ -134,18 +134,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) { errno = ENAMETOOLONG; goto err1; } - if (rootd == 0) - (void)strcat(resolved, "/"); - (void)strcat(resolved, wbuf); + if (needslash) + (void)strlcat(resolved, "/", MAXPATHLEN); + (void)strlcat(resolved, wbuf, MAXPATHLEN); } /* Go back to where we came from. */