From 220a902afa4e096172926d498e1efac23e80deb7 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 6 Mar 2012 17:57:23 +0000 Subject: [PATCH] libgo: Update to weekly.2012-03-04 release. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@185010 138bc75d-0d04-0410-961f-82ee72b054a4 --- libgo/MERGE | 2 +- libgo/Makefile.am | 13 +- libgo/Makefile.in | 16 +- libgo/go/archive/zip/reader.go | 141 ++-- libgo/go/archive/zip/reader_test.go | 2 +- libgo/go/archive/zip/struct.go | 10 - libgo/go/archive/zip/writer.go | 155 ++-- libgo/go/bufio/bufio.go | 1 - libgo/go/crypto/ecdsa/ecdsa.go | 2 +- libgo/go/crypto/tls/root_darwin.go | 32 +- libgo/go/crypto/x509/verify.go | 4 +- libgo/go/crypto/x509/x509.go | 6 +- libgo/go/encoding/binary/binary.go | 8 +- libgo/go/encoding/gob/codec_test.go | 5 +- libgo/go/encoding/gob/debug.go | 5 +- libgo/go/encoding/gob/decode.go | 23 +- libgo/go/encoding/gob/dump.go | 1 + libgo/go/encoding/gob/encoder_test.go | 2 +- libgo/go/encoding/json/decode_test.go | 10 - libgo/go/encoding/json/encode.go | 18 +- libgo/go/encoding/json/encode_test.go | 19 + libgo/go/encoding/json/indent.go | 13 + libgo/go/encoding/xml/marshal_test.go | 16 +- libgo/go/exp/gotype/doc.go | 2 + libgo/go/exp/gotype/gotype.go | 8 +- libgo/go/exp/html/node.go | 2 +- libgo/go/exp/norm/forminfo.go | 6 +- libgo/go/exp/proxy/per_host.go | 2 +- libgo/go/exp/types/gcimporter.go | 12 +- libgo/go/exp/types/types.go | 4 +- libgo/go/go/ast/print.go | 2 +- libgo/go/go/build/build.go | 942 ++++++++++++++++++++++- libgo/go/go/build/build_test.go | 110 +-- libgo/go/go/build/cgotest/cgotest.go | 19 - libgo/go/go/build/cmdtest/main.go | 12 - libgo/go/go/build/dir.go | 705 ----------------- libgo/go/go/build/doc.go | 109 +++ libgo/go/go/build/path.go | 182 ----- libgo/go/go/build/pkgtest/pkgtest.go | 13 - libgo/go/go/build/pkgtest/sqrt_386_test.go | 1 - libgo/go/go/build/pkgtest/sqrt_amd64_test.go | 1 - libgo/go/go/build/pkgtest/sqrt_arm_test.go | 1 - libgo/go/go/build/pkgtest/sqrt_test.go | 9 - libgo/go/go/build/pkgtest/xsqrt_test.go | 9 - libgo/go/go/build/syslist_test.go | 2 +- libgo/go/go/build/testdata/other/file/file.go | 5 + libgo/go/go/build/testdata/other/main.go | 11 + libgo/go/go/doc/reader.go | 20 +- libgo/go/go/parser/parser.go | 17 + libgo/go/go/parser/parser_test.go | 46 ++ libgo/go/go/printer/nodes.go | 361 ++++----- libgo/go/go/printer/printer.go | 75 +- libgo/go/go/printer/printer_test.go | 5 +- libgo/go/go/printer/testdata/comments.golden | 85 ++ libgo/go/go/printer/testdata/comments.input | 85 ++ libgo/go/go/printer/testdata/declarations.golden | 10 +- libgo/go/go/printer/testdata/declarations.input | 6 +- libgo/go/go/printer/testdata/expressions.golden | 22 + libgo/go/go/printer/testdata/expressions.input | 22 + libgo/go/go/printer/testdata/expressions.raw | 22 + libgo/go/go/printer/testdata/parser.go | 2 +- libgo/go/go/printer/testdata/statements.golden | 76 ++ libgo/go/go/printer/testdata/statements.input | 76 ++ libgo/go/html/template/doc.go | 2 +- libgo/go/html/template/escape.go | 2 +- libgo/go/html/template/escape_test.go | 11 +- libgo/go/html/template/html.go | 2 +- libgo/go/io/io.go | 7 + libgo/go/io/pipe.go | 4 + libgo/go/math/const.go | 8 +- libgo/go/net/dial.go | 2 +- libgo/go/net/dial_test.go | 81 ++ libgo/go/net/dialgoogle_test.go | 15 +- libgo/go/net/http/cgi/child.go | 1 + libgo/go/net/http/cgi/host_test.go | 1 + libgo/go/net/http/cgi/matryoshka_test.go | 21 +- libgo/go/net/http/fs_test.go | 10 +- libgo/go/net/http/httptest/server.go | 36 +- libgo/go/net/http/httputil/dump.go | 16 +- libgo/go/net/http/httputil/dump_test.go | 12 + libgo/go/net/http/httputil/persist.go | 2 +- libgo/go/net/http/lex.go | 8 - libgo/go/net/http/sniff_test.go | 3 +- libgo/go/net/http/status.go | 2 + libgo/go/net/http/transfer.go | 2 +- libgo/go/net/http/transport.go | 6 +- libgo/go/net/http/transport_test.go | 31 + libgo/go/net/http/triv.go | 1 - libgo/go/net/interface.go | 77 +- libgo/go/net/interface_test.go | 45 -- libgo/go/net/lookup_plan9.go | 2 +- libgo/go/net/lookup_test.go | 39 +- libgo/go/net/mac.go | 84 ++ libgo/go/net/mac_test.go | 54 ++ libgo/go/net/net_test.go | 118 --- libgo/go/net/rpc/client.go | 2 +- libgo/go/net/rpc/server.go | 39 +- libgo/go/net/sockoptip_netbsd.go | 39 + libgo/go/net/timeout_test.go | 2 +- libgo/go/net/udp_test.go | 10 +- libgo/go/os/doc.go | 72 ++ libgo/go/os/exec.go | 2 +- libgo/go/os/exec_plan9.go | 44 +- libgo/go/os/exec_posix.go | 41 +- libgo/go/os/exec_unix.go | 16 +- libgo/go/os/exec_windows.go | 40 +- libgo/go/os/file.go | 2 +- libgo/go/os/os_test.go | 37 +- libgo/go/path/filepath/path.go | 1 + libgo/go/path/filepath/path_plan9.go | 2 +- libgo/go/path/filepath/path_unix.go | 2 +- libgo/go/path/filepath/path_windows.go | 3 +- libgo/go/reflect/all_test.go | 22 + libgo/go/reflect/deepequal.go | 10 +- libgo/go/reflect/type.go | 2 +- libgo/go/reflect/value.go | 16 +- libgo/go/runtime/pprof/pprof.go | 6 +- libgo/go/runtime/pprof/pprof_test.go | 13 +- libgo/go/strconv/extfloat.go | 2 +- libgo/go/strings/example_test.go | 1 + libgo/go/sync/example_test.go | 20 + libgo/go/sync/waitgroup.go | 15 - libgo/go/syscall/socket.go | 12 + libgo/go/testing/example.go | 10 +- libgo/go/testing/testing.go | 4 +- libgo/go/text/template/doc.go | 23 +- libgo/go/text/template/exec.go | 5 +- libgo/go/text/template/exec_test.go | 29 +- libgo/go/text/template/funcs.go | 48 ++ libgo/go/text/template/multi_test.go | 6 + libgo/go/text/template/parse/parse.go | 2 + libgo/go/text/template/parse/parse_test.go | 3 + libgo/go/text/template/template.go | 20 +- libgo/go/time/format.go | 8 - libgo/go/time/sleep_test.go | 7 +- libgo/go/time/time.go | 15 +- libgo/runtime/go-main.c | 2 +- libgo/runtime/lock_futex.c | 12 +- libgo/runtime/lock_sema.c | 11 + libgo/runtime/malloc.goc | 11 +- libgo/runtime/mgc0.c | 8 - libgo/runtime/mheap.c | 2 +- libgo/runtime/proc.c | 20 +- libgo/runtime/runtime.c | 15 + libgo/runtime/runtime.h | 15 + libgo/runtime/thread-linux.c | 10 + libgo/runtime/thread.c | 33 + 147 files changed, 3079 insertions(+), 2021 deletions(-) delete mode 100644 libgo/go/go/build/cgotest/cgotest.go delete mode 100644 libgo/go/go/build/cmdtest/main.go delete mode 100644 libgo/go/go/build/dir.go create mode 100644 libgo/go/go/build/doc.go delete mode 100644 libgo/go/go/build/path.go delete mode 100644 libgo/go/go/build/pkgtest/pkgtest.go delete mode 100644 libgo/go/go/build/pkgtest/sqrt_386_test.go delete mode 100644 libgo/go/go/build/pkgtest/sqrt_amd64_test.go delete mode 100644 libgo/go/go/build/pkgtest/sqrt_arm_test.go delete mode 100644 libgo/go/go/build/pkgtest/sqrt_test.go delete mode 100644 libgo/go/go/build/pkgtest/xsqrt_test.go create mode 100644 libgo/go/go/build/testdata/other/file/file.go create mode 100644 libgo/go/go/build/testdata/other/main.go create mode 100644 libgo/go/net/mac.go create mode 100644 libgo/go/net/mac_test.go create mode 100644 libgo/go/net/sockoptip_netbsd.go diff --git a/libgo/MERGE b/libgo/MERGE index 9605a8a..17d01ce 100644 --- a/libgo/MERGE +++ b/libgo/MERGE @@ -1,4 +1,4 @@ -96bd78e7d35e +f4470a54e6db The first line of this file holds the Mercurial revision number of the last merge done from the master library sources. diff --git a/libgo/Makefile.am b/libgo/Makefile.am index eb764df..d43f054 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -658,10 +658,17 @@ go_net_sock_file = go/net/sock_linux.go go_net_sockopt_file = go/net/sockopt_linux.go go_net_sockoptip_file = go/net/sockoptip_linux.go else +if LIBGO_IS_FREEBSD go_net_cgo_file = go/net/cgo_bsd.go go_net_sock_file = go/net/sock_bsd.go go_net_sockopt_file = go/net/sockopt_bsd.go -go_net_sockoptip_file = go/net/sockoptip_bsd.go +go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_freebsd.go +else +go_net_cgo_file = go/net/cgo_bsd.go +go_net_sock_file = go/net/sock_bsd.go +go_net_sockopt_file = go/net/sockopt_bsd.go +go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_netbsd.go +endif endif endif endif @@ -704,6 +711,7 @@ go_net_files = \ go/net/ipsock.go \ go/net/ipsock_posix.go \ go/net/lookup_unix.go \ + go/net/mac.go \ go/net/net.go \ go/net/parse.go \ go/net/pipe.go \ @@ -1126,8 +1134,7 @@ go_go_ast_files = \ go/go/ast/walk.go go_go_build_files = \ go/go/build/build.go \ - go/go/build/dir.go \ - go/go/build/path.go \ + go/go/build/doc.go \ syslist.go go_go_doc_files = \ go/go/doc/comment.go \ diff --git a/libgo/Makefile.in b/libgo/Makefile.in index 4604e56..418c787 100644 --- a/libgo/Makefile.in +++ b/libgo/Makefile.in @@ -1012,19 +1012,23 @@ go_mime_files = \ @LIBGO_IS_LINUX_FALSE@@LIBGO_IS_NETBSD_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@go_net_newpollserver_file = go/net/newpollserver.go @LIBGO_IS_RTEMS_TRUE@go_net_newpollserver_file = go/net/newpollserver_rtems.go -@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go +@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go +@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_cgo_file = go/net/cgo_bsd.go @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_cgo_file = go/net/cgo_linux.go @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_cgo_file = go/net/cgo_linux.go @LIBGO_IS_LINUX_TRUE@go_net_cgo_file = go/net/cgo_linux.go -@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go +@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go +@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sock_file = go/net/sock_bsd.go @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sock_file = go/net/sock_linux.go @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sock_file = go/net/sock_linux.go @LIBGO_IS_LINUX_TRUE@go_net_sock_file = go/net/sock_linux.go -@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go +@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go +@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockopt_file = go/net/sockopt_bsd.go @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sockopt_file = go/net/sockopt_linux.go @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sockopt_file = go/net/sockopt_linux.go @LIBGO_IS_LINUX_TRUE@go_net_sockopt_file = go/net/sockopt_linux.go -@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go +@LIBGO_IS_FREEBSD_FALSE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_netbsd.go +@LIBGO_IS_FREEBSD_TRUE@@LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_FALSE@go_net_sockoptip_file = go/net/sockoptip_bsd.go go/net/sockoptip_freebsd.go @LIBGO_IS_IRIX_FALSE@@LIBGO_IS_LINUX_FALSE@@LIBGO_IS_SOLARIS_TRUE@go_net_sockoptip_file = go/net/sockoptip_linux.go @LIBGO_IS_IRIX_TRUE@@LIBGO_IS_LINUX_FALSE@go_net_sockoptip_file = go/net/sockoptip_linux.go @LIBGO_IS_LINUX_TRUE@go_net_sockoptip_file = go/net/sockoptip_linux.go @@ -1055,6 +1059,7 @@ go_net_files = \ go/net/ipsock.go \ go/net/ipsock_posix.go \ go/net/lookup_unix.go \ + go/net/mac.go \ go/net/net.go \ go/net/parse.go \ go/net/pipe.go \ @@ -1467,8 +1472,7 @@ go_go_ast_files = \ go_go_build_files = \ go/go/build/build.go \ - go/go/build/dir.go \ - go/go/build/path.go \ + go/go/build/doc.go \ syslist.go go_go_doc_files = \ diff --git a/libgo/go/archive/zip/reader.go b/libgo/go/archive/zip/reader.go index c300986..f3826dc 100644 --- a/libgo/go/archive/zip/reader.go +++ b/libgo/go/archive/zip/reader.go @@ -169,48 +169,21 @@ func (r *checksumReader) Read(b []byte) (n int, err error) { func (r *checksumReader) Close() error { return r.rc.Close() } -func readFileHeader(f *File, r io.Reader) error { - var b [fileHeaderLen]byte - if _, err := io.ReadFull(r, b[:]); err != nil { - return err - } - c := binary.LittleEndian - if sig := c.Uint32(b[:4]); sig != fileHeaderSignature { - return ErrFormat - } - f.ReaderVersion = c.Uint16(b[4:6]) - f.Flags = c.Uint16(b[6:8]) - f.Method = c.Uint16(b[8:10]) - f.ModifiedTime = c.Uint16(b[10:12]) - f.ModifiedDate = c.Uint16(b[12:14]) - f.CRC32 = c.Uint32(b[14:18]) - f.CompressedSize = c.Uint32(b[18:22]) - f.UncompressedSize = c.Uint32(b[22:26]) - filenameLen := int(c.Uint16(b[26:28])) - extraLen := int(c.Uint16(b[28:30])) - d := make([]byte, filenameLen+extraLen) - if _, err := io.ReadFull(r, d); err != nil { - return err - } - f.Name = string(d[:filenameLen]) - f.Extra = d[filenameLen:] - return nil -} - // findBodyOffset does the minimum work to verify the file has a header // and returns the file body offset. func (f *File) findBodyOffset() (int64, error) { r := io.NewSectionReader(f.zipr, f.headerOffset, f.zipsize-f.headerOffset) - var b [fileHeaderLen]byte - if _, err := io.ReadFull(r, b[:]); err != nil { + var buf [fileHeaderLen]byte + if _, err := io.ReadFull(r, buf[:]); err != nil { return 0, err } - c := binary.LittleEndian - if sig := c.Uint32(b[:4]); sig != fileHeaderSignature { + b := readBuf(buf[:]) + if sig := b.uint32(); sig != fileHeaderSignature { return 0, ErrFormat } - filenameLen := int(c.Uint16(b[26:28])) - extraLen := int(c.Uint16(b[28:30])) + b = b[22:] // skip over most of the header + filenameLen := int(b.uint16()) + extraLen := int(b.uint16()) return int64(fileHeaderLen + filenameLen + extraLen), nil } @@ -218,30 +191,29 @@ func (f *File) findBodyOffset() (int64, error) { // It returns io.ErrUnexpectedEOF if it cannot read a complete header, // and ErrFormat if it doesn't find a valid header signature. func readDirectoryHeader(f *File, r io.Reader) error { - var b [directoryHeaderLen]byte - if _, err := io.ReadFull(r, b[:]); err != nil { + var buf [directoryHeaderLen]byte + if _, err := io.ReadFull(r, buf[:]); err != nil { return err } - c := binary.LittleEndian - if sig := c.Uint32(b[:4]); sig != directoryHeaderSignature { + b := readBuf(buf[:]) + if sig := b.uint32(); sig != directoryHeaderSignature { return ErrFormat } - f.CreatorVersion = c.Uint16(b[4:6]) - f.ReaderVersion = c.Uint16(b[6:8]) - f.Flags = c.Uint16(b[8:10]) - f.Method = c.Uint16(b[10:12]) - f.ModifiedTime = c.Uint16(b[12:14]) - f.ModifiedDate = c.Uint16(b[14:16]) - f.CRC32 = c.Uint32(b[16:20]) - f.CompressedSize = c.Uint32(b[20:24]) - f.UncompressedSize = c.Uint32(b[24:28]) - filenameLen := int(c.Uint16(b[28:30])) - extraLen := int(c.Uint16(b[30:32])) - commentLen := int(c.Uint16(b[32:34])) - // startDiskNumber := c.Uint16(b[34:36]) // Unused - // internalAttributes := c.Uint16(b[36:38]) // Unused - f.ExternalAttrs = c.Uint32(b[38:42]) - f.headerOffset = int64(c.Uint32(b[42:46])) + f.CreatorVersion = b.uint16() + f.ReaderVersion = b.uint16() + f.Flags = b.uint16() + f.Method = b.uint16() + f.ModifiedTime = b.uint16() + f.ModifiedDate = b.uint16() + f.CRC32 = b.uint32() + f.CompressedSize = b.uint32() + f.UncompressedSize = b.uint32() + filenameLen := int(b.uint16()) + extraLen := int(b.uint16()) + commentLen := int(b.uint16()) + b = b[4:] // skipped start disk number and internal attributes (2x uint16) + f.ExternalAttrs = b.uint32() + f.headerOffset = int64(b.uint32()) d := make([]byte, filenameLen+extraLen+commentLen) if _, err := io.ReadFull(r, d); err != nil { return err @@ -253,30 +225,30 @@ func readDirectoryHeader(f *File, r io.Reader) error { } func readDataDescriptor(r io.Reader, f *File) error { - var b [dataDescriptorLen]byte - if _, err := io.ReadFull(r, b[:]); err != nil { + var buf [dataDescriptorLen]byte + if _, err := io.ReadFull(r, buf[:]); err != nil { return err } - c := binary.LittleEndian - f.CRC32 = c.Uint32(b[:4]) - f.CompressedSize = c.Uint32(b[4:8]) - f.UncompressedSize = c.Uint32(b[8:12]) + b := readBuf(buf[:]) + f.CRC32 = b.uint32() + f.CompressedSize = b.uint32() + f.UncompressedSize = b.uint32() return nil } func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) { // look for directoryEndSignature in the last 1k, then in the last 65k - var b []byte + var buf []byte for i, bLen := range []int64{1024, 65 * 1024} { if bLen > size { bLen = size } - b = make([]byte, int(bLen)) - if _, err := r.ReadAt(b, size-bLen); err != nil && err != io.EOF { + buf = make([]byte, int(bLen)) + if _, err := r.ReadAt(buf, size-bLen); err != nil && err != io.EOF { return nil, err } - if p := findSignatureInBlock(b); p >= 0 { - b = b[p:] + if p := findSignatureInBlock(buf); p >= 0 { + buf = buf[p:] break } if i == 1 || bLen == size { @@ -285,16 +257,21 @@ func readDirectoryEnd(r io.ReaderAt, size int64) (dir *directoryEnd, err error) } // read header into struct - c := binary.LittleEndian - d := new(directoryEnd) - d.diskNbr = c.Uint16(b[4:6]) - d.dirDiskNbr = c.Uint16(b[6:8]) - d.dirRecordsThisDisk = c.Uint16(b[8:10]) - d.directoryRecords = c.Uint16(b[10:12]) - d.directorySize = c.Uint32(b[12:16]) - d.directoryOffset = c.Uint32(b[16:20]) - d.commentLen = c.Uint16(b[20:22]) - d.comment = string(b[22 : 22+int(d.commentLen)]) + b := readBuf(buf[4:]) // skip signature + d := &directoryEnd{ + diskNbr: b.uint16(), + dirDiskNbr: b.uint16(), + dirRecordsThisDisk: b.uint16(), + directoryRecords: b.uint16(), + directorySize: b.uint32(), + directoryOffset: b.uint32(), + commentLen: b.uint16(), + } + l := int(d.commentLen) + if l > len(b) { + return nil, errors.New("zip: invalid comment length") + } + d.comment = string(b[:l]) return d, nil } @@ -311,3 +288,17 @@ func findSignatureInBlock(b []byte) int { } return -1 } + +type readBuf []byte + +func (b *readBuf) uint16() uint16 { + v := binary.LittleEndian.Uint16(*b) + *b = (*b)[2:] + return v +} + +func (b *readBuf) uint32() uint32 { + v := binary.LittleEndian.Uint32(*b) + *b = (*b)[4:] + return v +} diff --git a/libgo/go/archive/zip/reader_test.go b/libgo/go/archive/zip/reader_test.go index ea9e002..066a615 100644 --- a/libgo/go/archive/zip/reader_test.go +++ b/libgo/go/archive/zip/reader_test.go @@ -165,7 +165,7 @@ func readTestZip(t *testing.T, zt ZipTest) { t.Errorf("%s: comment=%q, want %q", zt.Name, z.Comment, zt.Comment) } if len(z.File) != len(zt.File) { - t.Errorf("%s: file count=%d, want %d", zt.Name, len(z.File), len(zt.File)) + t.Fatalf("%s: file count=%d, want %d", zt.Name, len(z.File), len(zt.File)) } // test read of each file diff --git a/libgo/go/archive/zip/struct.go b/libgo/go/archive/zip/struct.go index 35dcec6..fdbd16d 100644 --- a/libgo/go/archive/zip/struct.go +++ b/libgo/go/archive/zip/struct.go @@ -100,16 +100,6 @@ type directoryEnd struct { comment string } -func recoverError(errp *error) { - if e := recover(); e != nil { - if err, ok := e.(error); ok { - *errp = err - return - } - panic(e) - } -} - // msDosTimeToTime converts an MS-DOS date and time into a time.Time. // The resolution is 2s. // See: http://msdn.microsoft.com/en-us/library/ms724247(v=VS.85).aspx diff --git a/libgo/go/archive/zip/writer.go b/libgo/go/archive/zip/writer.go index c591aed..b2cc55b 100644 --- a/libgo/go/archive/zip/writer.go +++ b/libgo/go/archive/zip/writer.go @@ -37,10 +37,10 @@ func NewWriter(w io.Writer) *Writer { // Close finishes writing the zip file by writing the central directory. // It does not (and can not) close the underlying writer. -func (w *Writer) Close() (err error) { +func (w *Writer) Close() error { if w.last != nil && !w.last.closed { - if err = w.last.close(); err != nil { - return + if err := w.last.close(); err != nil { + return err } w.last = nil } @@ -49,43 +49,55 @@ func (w *Writer) Close() (err error) { } w.closed = true - defer recoverError(&err) - // write central directory start := w.cw.count for _, h := range w.dir { - write(w.cw, uint32(directoryHeaderSignature)) - write(w.cw, h.CreatorVersion) - write(w.cw, h.ReaderVersion) - write(w.cw, h.Flags) - write(w.cw, h.Method) - write(w.cw, h.ModifiedTime) - write(w.cw, h.ModifiedDate) - write(w.cw, h.CRC32) - write(w.cw, h.CompressedSize) - write(w.cw, h.UncompressedSize) - write(w.cw, uint16(len(h.Name))) - write(w.cw, uint16(len(h.Extra))) - write(w.cw, uint16(len(h.Comment))) - write(w.cw, uint16(0)) // disk number start - write(w.cw, uint16(0)) // internal file attributes - write(w.cw, h.ExternalAttrs) - write(w.cw, h.offset) - writeBytes(w.cw, []byte(h.Name)) - writeBytes(w.cw, h.Extra) - writeBytes(w.cw, []byte(h.Comment)) + var buf [directoryHeaderLen]byte + b := writeBuf(buf[:]) + b.uint32(uint32(directoryHeaderSignature)) + b.uint16(h.CreatorVersion) + b.uint16(h.ReaderVersion) + b.uint16(h.Flags) + b.uint16(h.Method) + b.uint16(h.ModifiedTime) + b.uint16(h.ModifiedDate) + b.uint32(h.CRC32) + b.uint32(h.CompressedSize) + b.uint32(h.UncompressedSize) + b.uint16(uint16(len(h.Name))) + b.uint16(uint16(len(h.Extra))) + b.uint16(uint16(len(h.Comment))) + b = b[4:] // skip disk number start and internal file attr (2x uint16) + b.uint32(h.ExternalAttrs) + b.uint32(h.offset) + if _, err := w.cw.Write(buf[:]); err != nil { + return err + } + if _, err := io.WriteString(w.cw, h.Name); err != nil { + return err + } + if _, err := w.cw.Write(h.Extra); err != nil { + return err + } + if _, err := io.WriteString(w.cw, h.Comment); err != nil { + return err + } } end := w.cw.count // write end record - write(w.cw, uint32(directoryEndSignature)) - write(w.cw, uint16(0)) // disk number - write(w.cw, uint16(0)) // disk number where directory starts - write(w.cw, uint16(len(w.dir))) // number of entries this disk - write(w.cw, uint16(len(w.dir))) // number of entries total - write(w.cw, uint32(end-start)) // size of directory - write(w.cw, uint32(start)) // start of directory - write(w.cw, uint16(0)) // size of comment + var buf [directoryEndLen]byte + b := writeBuf(buf[:]) + b.uint32(uint32(directoryEndSignature)) + b = b[4:] // skip over disk number and first disk number (2x uint16) + b.uint16(uint16(len(w.dir))) // number of entries this disk + b.uint16(uint16(len(w.dir))) // number of entries total + b.uint32(uint32(end - start)) // size of directory + b.uint32(uint32(start)) // start of directory + // skipped size of comment (always zero) + if _, err := w.cw.Write(buf[:]); err != nil { + return err + } return w.cw.w.(*bufio.Writer).Flush() } @@ -152,22 +164,28 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) { return fw, nil } -func writeHeader(w io.Writer, h *FileHeader) (err error) { - defer recoverError(&err) - write(w, uint32(fileHeaderSignature)) - write(w, h.ReaderVersion) - write(w, h.Flags) - write(w, h.Method) - write(w, h.ModifiedTime) - write(w, h.ModifiedDate) - write(w, h.CRC32) - write(w, h.CompressedSize) - write(w, h.UncompressedSize) - write(w, uint16(len(h.Name))) - write(w, uint16(len(h.Extra))) - writeBytes(w, []byte(h.Name)) - writeBytes(w, h.Extra) - return nil +func writeHeader(w io.Writer, h *FileHeader) error { + var buf [fileHeaderLen]byte + b := writeBuf(buf[:]) + b.uint32(uint32(fileHeaderSignature)) + b.uint16(h.ReaderVersion) + b.uint16(h.Flags) + b.uint16(h.Method) + b.uint16(h.ModifiedTime) + b.uint16(h.ModifiedDate) + b.uint32(h.CRC32) + b.uint32(h.CompressedSize) + b.uint32(h.UncompressedSize) + b.uint16(uint16(len(h.Name))) + b.uint16(uint16(len(h.Extra))) + if _, err := w.Write(buf[:]); err != nil { + return err + } + if _, err := io.WriteString(w, h.Name); err != nil { + return err + } + _, err := w.Write(h.Extra) + return err } type fileWriter struct { @@ -188,13 +206,13 @@ func (w *fileWriter) Write(p []byte) (int, error) { return w.rawCount.Write(p) } -func (w *fileWriter) close() (err error) { +func (w *fileWriter) close() error { if w.closed { return errors.New("zip: file closed twice") } w.closed = true - if err = w.comp.Close(); err != nil { - return + if err := w.comp.Close(); err != nil { + return err } // update FileHeader @@ -204,12 +222,13 @@ func (w *fileWriter) close() (err error) { fh.UncompressedSize = uint32(w.rawCount.count) // write data descriptor - defer recoverError(&err) - write(w.zipw, fh.CRC32) - write(w.zipw, fh.CompressedSize) - write(w.zipw, fh.UncompressedSize) - - return nil + var buf [dataDescriptorLen]byte + b := writeBuf(buf[:]) + b.uint32(fh.CRC32) + b.uint32(fh.CompressedSize) + b.uint32(fh.UncompressedSize) + _, err := w.zipw.Write(buf[:]) + return err } type countWriter struct { @@ -231,18 +250,14 @@ func (w nopCloser) Close() error { return nil } -func write(w io.Writer, data interface{}) { - if err := binary.Write(w, binary.LittleEndian, data); err != nil { - panic(err) - } +type writeBuf []byte + +func (b *writeBuf) uint16(v uint16) { + binary.LittleEndian.PutUint16(*b, v) + *b = (*b)[2:] } -func writeBytes(w io.Writer, b []byte) { - n, err := w.Write(b) - if err != nil { - panic(err) - } - if n != len(b) { - panic(io.ErrShortWrite) - } +func (b *writeBuf) uint32(v uint32) { + binary.LittleEndian.PutUint32(*b, v) + *b = (*b)[4:] } diff --git a/libgo/go/bufio/bufio.go b/libgo/go/bufio/bufio.go index 6f3b1ee..b44d0e7 100644 --- a/libgo/go/bufio/bufio.go +++ b/libgo/go/bufio/bufio.go @@ -23,7 +23,6 @@ var ( ErrInvalidUnreadRune = errors.New("bufio: invalid use of UnreadRune") ErrBufferFull = errors.New("bufio: buffer full") ErrNegativeCount = errors.New("bufio: negative count") - errInternal = errors.New("bufio: internal error") ) // Buffered input. diff --git a/libgo/go/crypto/ecdsa/ecdsa.go b/libgo/go/crypto/ecdsa/ecdsa.go index d2f7d8f..b28239b 100644 --- a/libgo/go/crypto/ecdsa/ecdsa.go +++ b/libgo/go/crypto/ecdsa/ecdsa.go @@ -7,7 +7,7 @@ package ecdsa // References: -// [NSA]: Suite B implementor's guide to FIPS 186-3, +// [NSA]: Suite B implementer's guide to FIPS 186-3, // http://www.nsa.gov/ia/_files/ecdsa.pdf // [SECG]: SECG, SEC1 // http://www.secg.org/download/aid-780/sec1-v2.pdf diff --git a/libgo/go/crypto/tls/root_darwin.go b/libgo/go/crypto/tls/root_darwin.go index db1b18b..911a9a6 100644 --- a/libgo/go/crypto/tls/root_darwin.go +++ b/libgo/go/crypto/tls/root_darwin.go @@ -5,11 +5,9 @@ package tls /* -// Note: We disable -Werror here because the code in this file uses a deprecated API to stay -// compatible with both Mac OS X 10.6 and 10.7. Using a deprecated function on Darwin generates -// a warning. -#cgo CFLAGS: -Wno-error -Wno-deprecated-declarations +#cgo CFLAGS: -mmacosx-version-min=10.6 -D__MAC_OS_X_VERSION_MAX_ALLOWED=1060 #cgo LDFLAGS: -framework CoreFoundation -framework Security + #include #include @@ -40,26 +38,12 @@ int FetchPEMRoots(CFDataRef *pemRoots) { continue; } - // SecKeychainImportExport is deprecated in >= OS X 10.7, and has been replaced by - // SecItemExport. If we're built on a host with a Lion SDK, this code gets conditionally - // included in the output, also for binaries meant for 10.6. - // - // To make sure that we run on both Mac OS X 10.6 and 10.7 we use weak linking - // and check whether SecItemExport is available before we attempt to call it. On - // 10.6, this won't be the case, and we'll fall back to calling SecKeychainItemExport. -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 - if (SecItemExport) { - err = SecItemExport(cert, kSecFormatX509Cert, kSecItemPemArmour, NULL, &data); - if (err != noErr) { - continue; - } - } else -#endif - if (data == NULL) { - err = SecKeychainItemExport(cert, kSecFormatX509Cert, kSecItemPemArmour, NULL, &data); - if (err != noErr) { - continue; - } + // Note: SecKeychainItemExport is deprecated as of 10.7 in favor of SecItemExport. + // Once we support weak imports via cgo we should prefer that, and fall back to this + // for older systems. + err = SecKeychainItemExport(cert, kSecFormatX509Cert, kSecItemPemArmour, NULL, &data); + if (err != noErr) { + continue; } if (data != NULL) { diff --git a/libgo/go/crypto/x509/verify.go b/libgo/go/crypto/x509/verify.go index 87b1cb7..3859dd8 100644 --- a/libgo/go/crypto/x509/verify.go +++ b/libgo/go/crypto/x509/verify.go @@ -135,8 +135,8 @@ func (c *Certificate) isValid(certType int, opts *VerifyOptions) error { // Verify attempts to verify c by building one or more chains from c to a // certificate in opts.roots, using certificates in opts.Intermediates if -// needed. If successful, it returns one or chains where the first element of -// the chain is c and the last element is from opts.Roots. +// needed. If successful, it returns one or more chains where the first +// element of the chain is c and the last element is from opts.Roots. // // WARNING: this doesn't do any revocation checking. func (c *Certificate) Verify(opts VerifyOptions) (chains [][]*Certificate, err error) { diff --git a/libgo/go/crypto/x509/x509.go b/libgo/go/crypto/x509/x509.go index 3116525..f5da86b 100644 --- a/libgo/go/crypto/x509/x509.go +++ b/libgo/go/crypto/x509/x509.go @@ -153,7 +153,7 @@ const ( // // md2WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 2 } // -// md5WithRSAEncryption OBJECT IDENTIFER ::= { pkcs-1 4 } +// md5WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 4 } // // sha-1WithRSAEncryption OBJECT IDENTIFIER ::= { pkcs-1 5 } // @@ -172,9 +172,9 @@ const ( // // RFC 5758 3.1 DSA Signature Algorithms // -// dsaWithSha356 OBJECT IDENTIFER ::= { +// dsaWithSha256 OBJECT IDENTIFIER ::= { // joint-iso-ccitt(2) country(16) us(840) organization(1) gov(101) -// algorithms(4) id-dsa-with-sha2(3) 2} +// csor(3) algorithms(4) id-dsa-with-sha2(3) 2} // var ( oidSignatureMD2WithRSA = asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 1, 2} diff --git a/libgo/go/encoding/binary/binary.go b/libgo/go/encoding/binary/binary.go index b26b1bb..02f090d 100644 --- a/libgo/go/encoding/binary/binary.go +++ b/libgo/go/encoding/binary/binary.go @@ -29,17 +29,13 @@ type ByteOrder interface { String() string } -// This is byte instead of struct{} so that it can be compared, -// allowing, e.g., order == binary.LittleEndian. -type unused byte - // LittleEndian is the little-endian implementation of ByteOrder. var LittleEndian littleEndian // BigEndian is the big-endian implementation of ByteOrder. var BigEndian bigEndian -type littleEndian unused +type littleEndian struct{} func (littleEndian) Uint16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 } @@ -79,7 +75,7 @@ func (littleEndian) String() string { return "LittleEndian" } func (littleEndian) GoString() string { return "binary.LittleEndian" } -type bigEndian unused +type bigEndian struct{} func (bigEndian) Uint16(b []byte) uint16 { return uint16(b[1]) | uint16(b[0])<<8 } diff --git a/libgo/go/encoding/gob/codec_test.go b/libgo/go/encoding/gob/codec_test.go index d365f82..ebcbb78 100644 --- a/libgo/go/encoding/gob/codec_test.go +++ b/libgo/go/encoding/gob/codec_test.go @@ -1455,11 +1455,14 @@ func TestFuzz(t *testing.T) { func TestFuzzRegressions(t *testing.T) { // An instance triggering a type name of length ~102 GB. testFuzz(t, 1328492090837718000, 100, new(float32)) + // An instance triggering a type name of 1.6 GB. + // Commented out because it takes 5m to run. + //testFuzz(t, 1330522872628565000, 100, new(int)) } func testFuzz(t *testing.T, seed int64, n int, input ...interface{}) { - t.Logf("seed=%d n=%d\n", seed, n) for _, e := range input { + t.Logf("seed=%d n=%d e=%T", seed, n, e) rng := rand.New(rand.NewSource(seed)) for i := 0; i < n; i++ { encFuzzDec(rng, e) diff --git a/libgo/go/encoding/gob/debug.go b/libgo/go/encoding/gob/debug.go index b54ef46..31d1351 100644 --- a/libgo/go/encoding/gob/debug.go +++ b/libgo/go/encoding/gob/debug.go @@ -3,14 +3,15 @@ // license that can be found in the LICENSE file. // Delete the next line to include in the gob package. -// +build gob-debug +// +build ignore package gob // This file is not normally included in the gob package. Used only for debugging the package itself. -// Add debug.go to the files listed in the Makefile to add Debug to the gob package. // Except for reading uints, it is an implementation of a reader that is independent of // the one implemented by Decoder. +// To enable the Debug function, delete the +build ignore line above and do +// go install import ( "bytes" diff --git a/libgo/go/encoding/gob/decode.go b/libgo/go/encoding/gob/decode.go index a0bb985..0708a83 100644 --- a/libgo/go/encoding/gob/decode.go +++ b/libgo/go/encoding/gob/decode.go @@ -392,12 +392,12 @@ func decUint8Slice(i *decInstr, state *decoderState, p unsafe.Pointer) { } p = *(*unsafe.Pointer)(p) } - n := int(state.decodeUint()) - if n < 0 { - errorf("negative length decoding []byte") + n := state.decodeUint() + if n > uint64(state.b.Len()) { + errorf("length of []byte exceeds input size (%d bytes)", n) } slice := (*[]uint8)(p) - if cap(*slice) < n { + if uint64(cap(*slice)) < n { *slice = make([]uint8, n) } else { *slice = (*slice)[0:n] @@ -417,7 +417,11 @@ func decString(i *decInstr, state *decoderState, p unsafe.Pointer) { } p = *(*unsafe.Pointer)(p) } - b := make([]byte, state.decodeUint()) + n := state.decodeUint() + if n > uint64(state.b.Len()) { + errorf("string length exceeds input size (%d bytes)", n) + } + b := make([]byte, n) state.b.Read(b) // It would be a shame to do the obvious thing here, // *(*string)(p) = string(b) @@ -647,7 +651,11 @@ func (dec *Decoder) ignoreMap(state *decoderState, keyOp, elemOp decOp) { // decodeSlice decodes a slice and stores the slice header through p. // Slices are encoded as an unsigned length followed by the elements. func (dec *Decoder) decodeSlice(atyp reflect.Type, state *decoderState, p uintptr, elemOp decOp, elemWid uintptr, indir, elemIndir int, ovfl error) { - n := int(uintptr(state.decodeUint())) + nr := state.decodeUint() + if nr > uint64(state.b.Len()) { + errorf("length of slice exceeds input size (%d elements)", nr) + } + n := int(nr) if indir > 0 { up := unsafe.Pointer(p) if *(*unsafe.Pointer)(up) == nil { @@ -702,6 +710,9 @@ func (dec *Decoder) decodeInterface(ityp reflect.Type, state *decoderState, p ui *(*[2]uintptr)(unsafe.Pointer(p)) = ivalue.InterfaceData() return } + if len(name) > 1024 { + errorf("name too long (%d bytes): %.20q...", len(name), name) + } // The concrete type must be registered. typ, ok := nameToConcreteType[name] if !ok { diff --git a/libgo/go/encoding/gob/dump.go b/libgo/go/encoding/gob/dump.go index e23a11e..17238c9 100644 --- a/libgo/go/encoding/gob/dump.go +++ b/libgo/go/encoding/gob/dump.go @@ -7,6 +7,7 @@ package main // Need to compile package gob with debug.go to build this program. +// See comments in debug.go for how to do this. import ( "encoding/gob" diff --git a/libgo/go/encoding/gob/encoder_test.go b/libgo/go/encoding/gob/encoder_test.go index 3bfae30..050786d 100644 --- a/libgo/go/encoding/gob/encoder_test.go +++ b/libgo/go/encoding/gob/encoder_test.go @@ -709,7 +709,7 @@ func TestGobPtrSlices(t *testing.T) { t.Fatal("decode:", err) } if !reflect.DeepEqual(in, out) { - t.Fatal("got %v; wanted %v", out, in) + t.Fatalf("got %v; wanted %v", out, in) } } diff --git a/libgo/go/encoding/json/decode_test.go b/libgo/go/encoding/json/decode_test.go index 0eec586..d758758 100644 --- a/libgo/go/encoding/json/decode_test.go +++ b/libgo/go/encoding/json/decode_test.go @@ -239,16 +239,6 @@ func TestEscape(t *testing.T) { } } -func TestHTMLEscape(t *testing.T) { - b, err := MarshalForHTML("foobarbaz<>&quux") - if err != nil { - t.Fatalf("MarshalForHTML error: %v", err) - } - if !bytes.Equal(b, []byte(`"foobarbaz\u003c\u003e\u0026quux"`)) { - t.Fatalf("Unexpected encoding of \"<>&\": %s", b) - } -} - // WrongString is a struct that's misusing the ,string modifier. type WrongString struct { Message string `json:"result,string"` diff --git a/libgo/go/encoding/json/encode.go b/libgo/go/encoding/json/encode.go index 8a794b7..5425a3a 100644 --- a/libgo/go/encoding/json/encode.go +++ b/libgo/go/encoding/json/encode.go @@ -123,17 +123,6 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { return buf.Bytes(), nil } -// MarshalForHTML is like Marshal but applies HTMLEscape to the output. -func MarshalForHTML(v interface{}) ([]byte, error) { - b, err := Marshal(v) - if err != nil { - return nil, err - } - var buf bytes.Buffer - HTMLEscape(&buf, b) - return buf.Bytes(), nil -} - // HTMLEscape appends to dst the JSON-encoded src with <, >, and & // characters inside string literals changed to \u003c, \u003e, \u0026 // so that the JSON will be safe to embed inside HTML