diff options
author | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2003-09-23 18:08:35 +0000 |
commit | d59fd3e421aa81b8e5e118f3f806081df2aca879 (patch) | |
tree | 356a4e607edc979c625bb33db63c656d771478bd /openbsd-compat/realpath.c | |
parent | 7505658c58e96b8d270f1928a0e1fa7f3e0c266b (diff) | |
parent | 45431c9b4677608680cd071768cbf156b316a7e8 (diff) |
Merge 3.7.1p2 to the trunk. I have absolutely no idea yet whether this will
work.
Diffstat (limited to 'openbsd-compat/realpath.c')
-rw-r--r-- | openbsd-compat/realpath.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c index b9035ca22..77da14e7c 100644 --- a/openbsd-compat/realpath.c +++ b/openbsd-compat/realpath.c | |||
@@ -13,6 +13,9 @@ | |||
13 | * 2. Redistributions in binary form must reproduce the above copyright | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | 14 | * notice, this list of conditions and the following disclaimer in the |
15 | * documentation and/or other materials provided with the distribution. | 15 | * documentation and/or other materials provided with the distribution. |
16 | * 3. Neither the name of the University nor the names of its contributors | ||
17 | * may be used to endorse or promote products derived from this software | ||
18 | * without specific prior written permission. | ||
16 | * | 19 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
@@ -32,7 +35,7 @@ | |||
32 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) | 35 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) |
33 | 36 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | 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.10 2003/08/01 21:04:59 millert Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 39 | #endif /* LIBC_SCCS and not lint */ |
37 | 40 | ||
38 | #include <sys/param.h> | 41 | #include <sys/param.h> |
@@ -62,7 +65,7 @@ char * | |||
62 | realpath(const char *path, char *resolved) | 65 | realpath(const char *path, char *resolved) |
63 | { | 66 | { |
64 | struct stat sb; | 67 | struct stat sb; |
65 | int fd, n, rootd, serrno = 0; | 68 | int fd, n, needslash, serrno = 0; |
66 | char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; | 69 | char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; |
67 | int symlinks = 0; | 70 | int symlinks = 0; |
68 | 71 | ||
@@ -138,18 +141,18 @@ loop: | |||
138 | * happens if the last component is empty, or the dirname is root. | 141 | * happens if the last component is empty, or the dirname is root. |
139 | */ | 142 | */ |
140 | if (resolved[0] == '/' && resolved[1] == '\0') | 143 | if (resolved[0] == '/' && resolved[1] == '\0') |
141 | rootd = 1; | 144 | needslash = 0; |
142 | else | 145 | else |
143 | rootd = 0; | 146 | needslash = 1; |
144 | 147 | ||
145 | if (*wbuf) { | 148 | if (*wbuf) { |
146 | if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { | 149 | if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { |
147 | serrno = ENAMETOOLONG; | 150 | serrno = ENAMETOOLONG; |
148 | goto err1; | 151 | goto err1; |
149 | } | 152 | } |
150 | if (rootd == 0) | 153 | if (needslash == 0) |
151 | (void)strcat(resolved, "/"); | 154 | strlcat(resolved, "/", MAXPATHLEN); |
152 | (void)strcat(resolved, wbuf); | 155 | strlcat(resolved, wbuf, MAXPATHLEN); |
153 | } | 156 | } |
154 | 157 | ||
155 | /* Go back to where we came from. */ | 158 | /* Go back to where we came from. */ |