summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrad <>2003-08-03 02:29:29 +0000
committerbrad <>2003-08-03 02:29:29 +0000
commitc4a5e23a629462f7c5d45410243a6450fde919ee (patch)
tree5e439c640a259e8b3a47fbfa670fe711868e5d78
parentf1617cf3a6465e4bcee0aa9c5796426d1cbe5c3e (diff)
downloadopenbsd-c4a5e23a629462f7c5d45410243a6450fde919ee.tar.gz
openbsd-c4a5e23a629462f7c5d45410243a6450fde919ee.tar.bz2
openbsd-c4a5e23a629462f7c5d45410243a6450fde919ee.zip
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@
-rw-r--r--src/lib/libc/stdlib/realpath.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c
index d01b19e0f2..f9a36e4227 100644
--- a/src/lib/libc/stdlib/realpath.c
+++ b/src/lib/libc/stdlib/realpath.c
@@ -35,7 +35,7 @@
35 */ 35 */
36 36
37#if defined(LIBC_SCCS) && !defined(lint) 37#if defined(LIBC_SCCS) && !defined(lint)
38static char *rcsid = "$OpenBSD: realpath.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $"; 38static char *rcsid = "$OpenBSD: realpath.c,v 1.7.2.1 2003/08/03 02:29:29 brad Exp $";
39#endif /* LIBC_SCCS and not lint */ 39#endif /* LIBC_SCCS and not lint */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
@@ -60,7 +60,7 @@ realpath(path, resolved)
60 char *resolved; 60 char *resolved;
61{ 61{
62 struct stat sb; 62 struct stat sb;
63 int fd, n, rootd, serrno; 63 int fd, n, needslash, serrno;
64 char *p, *q, wbuf[MAXPATHLEN]; 64 char *p, *q, wbuf[MAXPATHLEN];
65 int symlinks = 0; 65 int symlinks = 0;
66 66
@@ -134,18 +134,18 @@ loop:
134 * happens if the last component is empty, or the dirname is root. 134 * happens if the last component is empty, or the dirname is root.
135 */ 135 */
136 if (resolved[0] == '/' && resolved[1] == '\0') 136 if (resolved[0] == '/' && resolved[1] == '\0')
137 rootd = 1; 137 needslash = 0;
138 else 138 else
139 rootd = 0; 139 needslash = 1;
140 140
141 if (*wbuf) { 141 if (*wbuf) {
142 if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { 142 if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) {
143 errno = ENAMETOOLONG; 143 errno = ENAMETOOLONG;
144 goto err1; 144 goto err1;
145 } 145 }
146 if (rootd == 0) 146 if (needslash)
147 (void)strcat(resolved, "/"); 147 (void)strlcat(resolved, "/", MAXPATHLEN);
148 (void)strcat(resolved, wbuf); 148 (void)strlcat(resolved, wbuf, MAXPATHLEN);
149 } 149 }
150 150
151 /* Go back to where we came from. */ 151 /* Go back to where we came from. */