Browse Source

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@
OPENBSD_3_2
brad 21 years ago
parent
commit
3495e82eba
1 changed files with 8 additions and 8 deletions
  1. +8
    -8
      src/lib/libc/stdlib/realpath.c

+ 8
- 8
src/lib/libc/stdlib/realpath.c View File

@ -35,7 +35,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #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 */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -60,7 +60,7 @@ realpath(path, resolved)
char *resolved; char *resolved;
{ {
struct stat sb; struct stat sb;
int fd, n, rootd, serrno;
int fd, n, needslash, serrno;
char *p, *q, wbuf[MAXPATHLEN]; char *p, *q, wbuf[MAXPATHLEN];
int symlinks = 0; int symlinks = 0;
@ -134,18 +134,18 @@ loop:
* happens if the last component is empty, or the dirname is root. * happens if the last component is empty, or the dirname is root.
*/ */
if (resolved[0] == '/' && resolved[1] == '\0') if (resolved[0] == '/' && resolved[1] == '\0')
rootd = 1;
needslash = 0;
else else
rootd = 0;
needslash = 1;
if (*wbuf) { if (*wbuf) {
if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) {
if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) {
errno = ENAMETOOLONG; errno = ENAMETOOLONG;
goto err1; 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. */ /* Go back to where we came from. */


Loading…
Cancel
Save