Date: Sat, 7 Jan 1995 12:59:10 -0500 From: Thomas David Rivers <rivers%ponds@ncren.net> To: freebsd-bugs@freefall.cdrom.com, freebsd-hackers@freefall.cdrom.com Subject: getwd() bug remains... Message-ID: <199501071759.MAA06088@ponds.UUCP>
next in thread | raw e-mail | index | archive | help
Several months ago I sparked a small debate about correcting getwd()
when the size of the argument buffer isn't large enough to contain
MAXPATHLEN characters.
In this instance, the call to getwd() *always* dumps core.
Although the man page does indicate that getwd of anything less
than MAXPATHLEN is a no-no, in my opinion, it shouldn't automatically
dump core no matter what. Certainly, that was not the behaviour getwd()
had in the past, and the entire point of the compat-43 routines is
to be compatible (as best as possible) with prior behaviour.
Unfortunately, when rebuilding some of my (admittedly very old) programs, I
ran into exactly the same problem again.
I discovered that lib/libc/compat-43/getwd.c had not yet been changed.
I proposed the following routine, which will only dump core when the
actual directory name is larger than the argument buffer, not every time:
char *
getwd(buf)
char *buf;
{
char tbuf[MAXPATHLEN];
if (getcwd(tbuf, MAXPATHLEN)) {
strcpy(buf, tbuf);
return buf;
}
(void)strcpy(buf, strerror(errno));
return((char *)NULL);
}
could someone _please_ commit this to 2.1 (or 2.0.5 if that ever occurs.)
- Thanks -
- Dave Rivers -
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199501071759.MAA06088>
