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.24.4.2 retrieving revision 1.28 diff -u -p -r1.24.4.2 -r1.28 --- src/lib/libc/gen/getcwd.c 2003/08/05 09:31:58 1.24.4.2 +++ src/lib/libc/gen/getcwd.c 2002/11/17 20:49:33 1.28 @@ -1,4 +1,4 @@ -/* $NetBSD: getcwd.c,v 1.24.4.2 2003/08/05 09:31:58 msaitoh Exp $ */ +/* $NetBSD: getcwd.c,v 1.28 2002/11/17 20:49:33 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.24.4.2 2003/08/05 09:31:58 msaitoh Exp $"); +__RCSID("$NetBSD: getcwd.c,v 1.28 2002/11/17 20:49:33 itojun Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -95,7 +95,7 @@ realpath(path, resolved) /* Save the starting point. */ if ((fd = open(".", O_RDONLY)) < 0) { - (void)strcpy(resolved, "."); + (void)strlcpy(resolved, ".", MAXPATHLEN); return (NULL); } @@ -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; }