freebsd-nq/lib/libc/gen
Bruce Evans b01f0b7d76 Obtained from: 1.1.5
getcwd() has two off-by-one bugs in FreeBSD-2.0:

1. getcwd(buf, size) fails when the size is just large enough.
2. getcwd(buf + 1, 1) incorrectly succeeds when the current directory
   is "/".  buf[0] and buf[2] are clobbered.

(I modified Bruce's original patch to return the proper error code
[ERANGE] in the case of #2, but otherwise... -DG)

This program demonstrates the bug:

---
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>

int main(void)
{
    char buf[5];
    int errors;

    errors = 0;
    if (chdir("/tmp") != 0) {
        perror("chdir");
        abort();
    }
    if (getcwd(buf, 5) == NULL) {
        perror("oops, getcwd failed for buffer size = size required");
        ++errors;
    }
    if (chdir("/") != 0) {
        perror("chdir");
        abort();
    }
    buf[0] = 0;
    buf[2] = 1;
    if (getcwd(buf + 1, 1) != NULL) {
        fprintf(stderr,
                "oops, getcwd succeeded for buffer size = one too small\n");
        ++errors;
    }
    if (buf[0] != 0) {
        fprintf(stderr,
                "oops, getcwd scribbled on memory before start of buffer\n");
        ++errors;
    }
    if (buf[2] != 1) {
        fprintf(stderr,
                "oops, getcwd scribbled on memory after end of buffer\n");
        ++errors;
    }
    exit(errors == 0 ? 0 : 1);
}
1994-12-12 01:29:13 +00:00
..
__xuname.c sysctl(3) can return an error (setting errno to ENOMEM) when the 1994-10-13 20:31:19 +00:00
_rand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
alarm.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
alarm.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
assert.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
clock.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
clock.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
closedir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
config_open.3 Added routines to read the canonical UNIX configuration file. This will 1994-11-13 20:47:44 +00:00
config.c Added routines to read the canonical UNIX configuration file. This will 1994-11-13 20:47:44 +00:00
confstr.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
confstr.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
crypt.3 document libcrypt and libcipher. 1994-09-08 19:46:57 +00:00
crypt.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ctermid.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ctermid.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ctime.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ctime.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
daemon.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
daemon.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
devname.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
devname.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
difftime.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
directory.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
disklabel.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
drand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
erand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
err.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
err.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
errlst.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
exec.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
exec.c Fix execl[e]. Multiple execle's failed because of bogus caching of the 1994-12-12 01:15:01 +00:00
fnmatch.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
fnmatch.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
frexp.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
fstab.c Make errors in /etc/fstab print the line numbers where they occured. 1994-09-08 09:21:00 +00:00
fts-compat.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
fts-compat.h BSD 4.4 Lite Include Sources 1994-05-24 09:57:34 +00:00
fts.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
fts.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getbootfile.3 Added getbootfile(3), for an easy C interface to the kern.bootfile MIB 1994-09-23 20:22:01 +00:00
getbootfile.c If sysctl() fails, return "/kernel" so as not to screw people who haven't 1994-09-24 00:10:13 +00:00
getbsize.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getbsize.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getcap.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getcap.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getcwd.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getcwd.c Obtained from: 1.1.5 1994-12-12 01:29:13 +00:00
getdiskbyname.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getdomainname.c Added YP domain name getting/setting support, for SunOS/old program 1994-08-08 00:40:24 +00:00
getfsent.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getgrent.3 Document YP support. 1994-09-20 22:02:20 +00:00
getgrent.c My implementation of YP group file support, modeled after the 1994-09-20 21:43:27 +00:00
getgrouplist.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getgrouplist.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
gethostname.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
gethostname.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getloadavg.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getloadavg.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getlogin.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getmntinfo.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getmntinfo.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getnetgrent.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getnetgrent.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getosreldate.c Oops, forgot to cvs add this file. 1994-08-10 06:27:35 +00:00
getpagesize.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getpagesize.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getpass.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getpass.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getpwent.3 Document YP support. 1994-09-20 22:02:20 +00:00
getpwent.c Second half of YP security hole fix. Needs updated password 1994-09-20 21:42:12 +00:00
getttyent.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getttyent.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getusershell.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getusershell.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
getvfsent.3 Document getvfsent() and kin. 1994-09-25 01:38:30 +00:00
getvfsent.c Fix so that people who don't have LKMs compiled in their kernels don't 1994-09-25 00:48:27 +00:00
glob.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
glob.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
initgroups.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
initgroups.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
isatty.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
isinf.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
jrand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
lcong48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
ldexp.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
lrand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
Makefile.inc Added routines to read the canonical UNIX configuration file. This will 1994-11-13 20:47:44 +00:00
modf.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
mrand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
msgctl.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
msgget.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
msgrcv.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
msgsnd.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
nice.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
nice.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
nlist.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
nlist.c Rewrite nlist to mmap the whole a.out file (at Davidg's suggestion). 1994-07-22 12:22:51 +00:00
nrand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
ntp_gettime.c Function in this module bloodly called 'gethostname' and linked 1994-09-19 22:04:28 +00:00
opendir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
pause.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
pause.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
popen.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
popen.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
psignal.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
psignal.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
pw_scan.c Maintain pw_fields, and output same to password database. 1994-09-20 01:15:08 +00:00
pw_scan.h BSD 4.4 Lite usr.sbin Sources 1994-05-26 05:23:31 +00:00
pwcache.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
pwcache.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
raise.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
raise.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
rand48.3 Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
rand48.h Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
readdir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
rewinddir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
scandir.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
scandir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
seed48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
seekdir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
semconfig.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
semctl.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
semget.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
semop.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
setdomainname.c Added YP domain name getting/setting support, for SunOS/old program 1994-08-08 00:40:24 +00:00
setflags.c Added $Id$ 1994-09-24 02:59:15 +00:00
setflagsbyname.c Added $Id$ 1994-09-24 02:59:15 +00:00
sethostname.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
setjmp.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
setjmperr.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
setmode.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
setmode.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
shmat.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
shmctl.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
shmdt.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
shmget.c Added SYSV ipc system calls. 1994-09-13 14:52:45 +00:00
siginterrupt.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
siginterrupt.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
siglist.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
signal.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
signal.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sigsetjmp.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sigsetops.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sigsetops.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sleep.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sleep.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
srand48.c Added *ran48 functions, and put them in the correct place this time. 1994-09-23 00:37:55 +00:00
strtofflags.c Added $Id$ 1994-09-24 02:59:15 +00:00
sysconf.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sysconf.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
sysctl.3 Remove CPU_COLORDISP, GIO_COLOR now exists 1994-10-18 03:42:18 +00:00
sysctl.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
syslog.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
syslog.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
tcgetpgrp.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
tcsendbreak.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
tcsetattr.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
tcsetpgrp.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
telldir.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
termios.c cfmakeraw(): set IGNBRK, clear IXOFF, INPCK per Bruce suggestion 1994-10-22 18:12:17 +00:00
time.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
time.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
times.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
times.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
timezone.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
timezone.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ttyname.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ttyname.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ttyslot.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
tzset.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ualarm.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
ualarm.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
uname.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
uname.c sysctl(3) can return an error (setting errno to ENOMEM) when the 1994-10-13 20:31:19 +00:00
unvis.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
unvis.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
usleep.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
usleep.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
utime.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
utime.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
valloc.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
valloc.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
vis.3 BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
vis.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
wait3.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
wait.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
waitpid.c BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00