Browse Source

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@
OPENBSD_3_4
millert 21 years ago
parent
commit
354e03d14f
1 changed files with 6 additions and 6 deletions
  1. +6
    -6
      src/lib/libc/stdlib/realpath.c

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

@ -31,7 +31,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: realpath.c,v 1.9 2003/06/02 20:18:38 millert Exp $";
static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -56,7 +56,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;
@ -130,16 +130,16 @@ 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)
if (needslash)
strlcat(resolved, "/", MAXPATHLEN); strlcat(resolved, "/", MAXPATHLEN);
strlcat(resolved, wbuf, MAXPATHLEN); strlcat(resolved, wbuf, MAXPATHLEN);
} }


Loading…
Cancel
Save