diff options
author | brad <> | 2003-08-03 02:17:03 +0000 |
---|---|---|
committer | brad <> | 2003-08-03 02:17:03 +0000 |
commit | 06330453788740869bd2ffcf287c741d75fe6fc6 (patch) | |
tree | 30de0e26f9d6e30827ff97b4e8ad8d66036b4155 | |
parent | 6c1b09d1f4c5f48d3dba5eeee76196e46a515464 (diff) | |
download | openbsd-06330453788740869bd2ffcf287c741d75fe6fc6.tar.gz openbsd-06330453788740869bd2ffcf287c741d75fe6fc6.tar.bz2 openbsd-06330453788740869bd2ffcf287c741d75fe6fc6.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.c | 16 |
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..852afe1df1 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) |
38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.7 2002/05/24 21:22:37 deraadt Exp $"; | 38 | static char *rcsid = "$OpenBSD: realpath.c,v 1.7.4.1 2003/08/03 02:17:03 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. */ |