freebsd-skq/lib/libc
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
..
amd64 Reenable sigsetjmp.S. Preserve the FP state. Rearrange offsets 1994-10-25 14:08:13 +00:00
compat-43 gethostid.2 is now gethostid.3. Instal the correct one. 1994-08-28 17:08:36 +00:00
db Added the mpool.3 manpage to the installed manpages. It is referred from the 1994-12-11 22:03:05 +00:00
gen Obtained from: 1.1.5 1994-12-12 01:29:13 +00:00
gmon Added support for kernel profiling to mcount.c 1994-09-15 16:00:41 +00:00
i386 Go back to Bruce's fix with a minor change that will allow a NULL string 1994-11-25 08:58:53 +00:00
locale Sync with ctype.h (remove EOF handling) 1994-10-09 11:20:55 +00:00
net In _gethostbydnsaddr(), force RES_RECURSE into _res.options. This is 1994-12-01 22:25:38 +00:00
quad BSD 4.4 Lite Lib Sources 1994-05-27 05:00:24 +00:00
regex First crack at making libc work with the new make macros. It compiles on 1994-08-05 01:19:12 +00:00
rpc Comment out the man page of rstat.1 from Makefile.inc. There is no rstat 1994-12-11 22:08:10 +00:00
stdio Date: Wed, 26 Oct 1994 15:44:49 -0600 1994-11-05 18:49:34 +00:00
stdlib u_int -> unsigned int, so that we don't have to include <sys/types.h> 1994-09-05 13:26:40 +00:00
stdtime Use latest Arthur Olson timezone code rather than that supplied with 1994-09-13 21:26:08 +00:00
string Obtained from: 386BSD-0.1 patchkit; also fixed in 1.1.5 1994-12-12 01:23:33 +00:00
sys Added sysarch system call which is used my i386_get/set_ltd.c and is needed 1994-11-17 10:50:55 +00:00
xdr More directory cleanup after YP merge. 1994-08-07 22:21:14 +00:00
yp Add back in the YP code from 1.1.5. (This attribution brought to you 1994-08-07 23:04:55 +00:00
Makefile Use latest Arthur Olson timezone code rather than that supplied with 1994-09-13 21:26:08 +00:00