]> Cypherpunks repositories - gostls13.git/commitdiff
fix infinite loop in Readdirnames: bufp > nbuf can happen
authorRuss Cox <rsc@golang.org>
Wed, 15 Apr 2009 01:52:39 +0000 (18:52 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 15 Apr 2009 01:52:39 +0000 (18:52 -0700)
after EOF has been hit, because nbuf is now 0 or -1.

discard old comment.

R=r
DELTA=3  (0 added, 0 deleted, 3 changed)
OCL=27463
CL=27465

src/lib/os/dir_amd64_darwin.go
src/lib/os/dir_amd64_linux.go
src/lib/os/file.go

index 76da8f4d9738e834a40641417ea293b6488f34e2..903eb28784ca6cf2fece6a711cd587a61d7f7278 100644 (file)
@@ -31,7 +31,7 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
        names = make([]string, 0, size);        // Empty with room to grow.
        for count != 0 {
                // Refill the buffer if necessary
-               if d.bufp == d.nbuf {
+               if d.bufp >= d.nbuf {
                        var errno int64;
                        // Final argument is (basep *int64) and the syscall doesn't take nil.
                        d.nbuf, errno = syscall.Getdirentries(file.fd, &d.buf[0], int64(len(d.buf)), new(int64));
index db42cfbabfa930f3c6380e01e31254c2c770f360..7ce5f13ad1881e59edb8cb6e51090373a46b8ab5 100644 (file)
@@ -40,7 +40,7 @@ func readdirnames(file *File, count int) (names []string, err *os.Error) {
        names = make([]string, 0, size);        // Empty with room to grow.
        for count != 0 {
                // Refill the buffer if necessary
-               if d.bufp == d.nbuf {
+               if d.bufp >= d.nbuf {
                        var errno int64;
                        dbuf := (*syscall.Dirent)(unsafe.Pointer(&d.buf[0]));
                        d.nbuf, errno = syscall.Getdents(file.fd, dbuf, int64(len(d.buf)));
index 9e98be697a6c96315a9450931e2db152e1564e3d..fa066eb7120699784e4f682e7e440c07c26664d1 100644 (file)
@@ -12,7 +12,7 @@ import (
 )
 
 // Auxiliary information if the File describes a directory
-type dirInfo struct {  // TODO(r): 6g bug means this can't be private
+type dirInfo struct {
        buf     []byte; // buffer for directory I/O
        nbuf    int64;  // length of buf; return value from Getdirentries
        bufp    int64;  // location of next record in buf.