Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/lib/libc/gen/getcwd.c,v retrieving revision 1.25.2.1 retrieving revision 1.27 diff -u -p -r1.25.2.1 -r1.27 --- src/lib/libc/gen/getcwd.c 2003/08/04 04:25:26 1.25.2.1 +++ src/lib/libc/gen/getcwd.c 2002/11/17 01:51:24 1.27 @@ -1,4 +1,4 @@ -/* $NetBSD: getcwd.c,v 1.25.2.1 2003/08/04 04:25:26 grant Exp $ */ +/* $NetBSD: getcwd.c,v 1.27 2002/11/17 01:51:24 itojun Exp $ */ /* * Copyright (c) 1989, 1991, 1993, 1995 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #else -__RCSID("$NetBSD: getcwd.c,v 1.25.2.1 2003/08/04 04:25:26 grant Exp $"); +__RCSID("$NetBSD: getcwd.c,v 1.27 2002/11/17 01:51:24 itojun Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,8 +107,7 @@ realpath(path, resolved) * if it is a directory, then change to that directory. * get the current directory name and append the basename. */ - (void)strncpy(resolved, path, MAXPATHLEN - 1); - resolved[MAXPATHLEN - 1] = '\0'; + (void)strlcpy(resolved, path, MAXPATHLEN); loop: q = strrchr(resolved, '/'); if (q != NULL) { @@ -134,7 +133,7 @@ loop: errno = ELOOP; goto err1; } - n = readlink(p, resolved, MAXPATHLEN); + n = readlink(p, resolved, MAXPATHLEN-1); if (n < 0) goto err1; resolved[n] = '\0'; @@ -170,8 +169,7 @@ loop: rootd = 0; if (*wbuf) { - if (strlen(resolved) + strlen(wbuf) + (rootd ? 0 : 1) + 1 > - MAXPATHLEN) { + if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { errno = ENAMETOOLONG; goto err1; }