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.30 retrieving revision 1.31 diff -u -p -r1.30 -r1.31 --- src/lib/libc/gen/getcwd.c 2003/08/03 04:14:00 1.30 +++ src/lib/libc/gen/getcwd.c 2003/08/03 04:35:50 1.31 @@ -1,4 +1,4 @@ -/* $NetBSD: getcwd.c,v 1.30 2003/08/03 04:14:00 itojun Exp $ */ +/* $NetBSD: getcwd.c,v 1.31 2003/08/03 04:35:50 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.30 2003/08/03 04:14:00 itojun Exp $"); +__RCSID("$NetBSD: getcwd.c,v 1.31 2003/08/03 04:35:50 itojun Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -107,7 +107,10 @@ realpath(path, resolved) * if it is a directory, then change to that directory. * get the current directory name and append the basename. */ - (void)strlcpy(resolved, path, MAXPATHLEN); + if (strlcpy(resolved, path, MAXPATHLEN) >= MAXPATHLEN) { + errno = ENAMETOOLONG; + goto err1; + } loop: q = strrchr(resolved, '/'); if (q != NULL) { @@ -150,7 +153,10 @@ loop: * Save the last component name and get the full pathname of * the current directory. */ - (void)strlcpy(wbuf, p, sizeof(wbuf)); + if (strlcpy(wbuf, p, sizeof(wbuf)) >= sizeof(wbuf)) { + errno = ENAMETOOLONG; + goto err1; + } /* * Call the inernal internal version of getcwd which @@ -175,8 +181,14 @@ loop: goto err1; } if (rootd == 0) - (void)strlcat(resolved, "/", MAXPATHLEN); - (void)strlcat(resolved, wbuf, MAXPATHLEN); + if (strlcat(resolved, "/", MAXPATHLEN) >= MAXPATHLEN) { + errno = ENAMETOOLONG; + goto err1; + } + if (strlcat(resolved, wbuf, MAXPATHLEN) >= MAXPATHLEN) { + errno = ENAMETOOLONG; + goto err1; + } } /* Go back to where we came from. */