be more pedantic to strlcpy/strcat errors

This commit is contained in:
itojun 2003-08-03 04:35:50 +00:00
parent 785d6ef678
commit 2e48312004
1 changed files with 18 additions and 6 deletions

View File

@ -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. */