[dev.unified] all: merge master (462b78f) into dev.unified

Merge List:

+ 2022-07-27 462b78fe70 misc/cgo/test: use fewer threads in TestSetgidStress in long mode
+ 2022-07-27 055113ef36 math/big: check buffer lengths in GobDecode
+ 2022-07-27 4248146154 net: document UDPConn.ReadFromUDPAddrPort's AddrPort result more
+ 2022-07-26 faf4e97200 net: fix WriteMsgUDPAddrPort addr handling
+ 2022-07-26 caa225dd29 doc/go1.19: note that updated race syso files require GNU ld 2.26
+ 2022-07-26 ceefd3a37b bytes: document that Reader.Reset affects the result of Size
+ 2022-07-26 3e97294663 runtime/cgo: use frame address to set g0 stack bound
+ 2022-07-25 24dc27a3c0 cmd/compile: fix blank label code
+ 2022-07-25 9fcc8b2c1e runtime: fix runtime.Breakpoint() on windows/arm64
+ 2022-07-25 795a88d0c3 cmd/go: add space after comma in 'go help test'
+ 2022-07-25 9eb3992ddd doc/go1.19: minor fixes
+ 2022-07-25 dcea1ee6e3 time: clarify documentation for allowed formats and add tests to prove them
+ 2022-07-25 37c8112b82 internal/fuzz: fix typo in function comments
+ 2022-07-25 850d547d2d doc/go1.19: expand crypto release notes
+ 2022-07-24 64f2829c9c runtime: fix typo in function comments
+ 2022-07-24 2ff563a00e cmd/compile/internal/noder: correct spelling errors for instantiation
+ 2022-07-22 c5da4fb7ac cmd/compile: make jump table symbol local
+ 2022-07-22 774fa58d1d A+C: delete AUTHORS and CONTRIBUTORS
+ 2022-07-21 2d655fb15a unsafe: document when Sizeof/Offsetof/Alignof are not constant
+ 2022-07-21 076c3d7f07 net/http: remove accidental heading in Head documentation
+ 2022-07-21 c4a6d3048b cmd/dist: enable race detector test on S390X
+ 2022-07-20 244c8b0500 cmd/cgo: allow cgo to pass strings or []bytes bigger than 1<<30
+ 2022-07-20 df38614bd7 test: use go tool from tree, not path
+ 2022-07-20 bb1749ba3b cmd/compile: improve GOAMD64=v1 violation test
+ 2022-07-19 176b63e711 crypto/internal/nistec,debug/gosym: fix typos

Change-Id: I96e5d60039381691dffd841e58927f0afff8c544
This commit is contained in:
Matthew Dempsky 2022-07-28 00:32:28 -07:00
commit 23554d4744
36 changed files with 389 additions and 4536 deletions

1505
AUTHORS

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -322,16 +322,58 @@ as well as support for rendering them to HTML, Markdown, and text.
</dd>
</dl><!-- archive/zip -->
<dl id="crypto/elliptic"><dt><a href="/pkg/crypto/elliptic/">crypto/elliptic</a></dt>
<dd>
<p><!-- CL 382995 -->
Operating on invalid curve points (those for which the
<code>IsOnCurve</code> method returns false, and which are never returned
by <code>Unmarshal</code> or by a <code>Curve</code> method operating on a
valid point) has always been undefined behavior and can lead to key
recovery attacks. If an invalid point is supplied to
<a href="/pkg/crypto/elliptic/#Marshal"><code>Marshal</code></a>,
<a href="/pkg/crypto/elliptic/#MarshalCompressed"><code>MarshalCompressed</code></a>,
<a href="/pkg/crypto/elliptic/#Curve.Add"><code>Add</code></a>,
<a href="/pkg/crypto/elliptic/#Curve.Double"><code>Double</code></a>, or
<a href="/pkg/crypto/elliptic/#Curve.ScalarMult"><code>ScalarMult</code></a>,
they will now panic.
</p>
<p><!-- golang.org/issue/52182 -->
<code>ScalarBaseMult</code> operations on the <code>P224</code>,
<code>P384</code>, and <code>P521</code> curves are now up to three
times faster, leading to similar speedups in some ECDSA operations. The
generic (not platform optimized) <code>P256</code> implementation was
replaced with one derived from a formally verified model; this might
lead to significant slowdowns on 32-bit platforms.
</p>
</dd>
</dl><!-- crypto/elliptic -->
<dl id="crypto/rand"><dt><a href="/pkg/crypto/rand/">crypto/rand</a></dt>
<dd>
<p><!-- CL 370894 --><!-- CL 390038 -->
<a href="/pkg/crypto/rand/#Read"><code>Read</code></a> no longer buffers
random data obtained from the operating system between calls.
random data obtained from the operating system between calls. Applications
that perform many small reads at high frequency might choose to wrap
<a href="/pkg/crypto/rand/#Reader"><code>Reader</code></a> in a
<a href="/pkg/bufio/#Reader"><code>bufio.Reader</code></a> for performance
reasons, taking care to use
<a href="/pkg/io/#ReadFull"><code>io.ReadFull</code></a>
to ensure no partial reads occur.
</p>
<p><!-- CL 375215 -->
On Plan 9, <code>Read</code> has been reimplemented, replacing the ANSI
X9.31 algorithm with fast key erasure.
X9.31 algorithm with a fast key erasure generator.
</p>
<p><!-- CL 391554 --><!-- CL 387554 -->
The <a href="/pkg/crypto/rand/#Prime"><code>Prime</code></a>
implementation was simplified. This will lead to different outputs for the
same random stream compared to the previous implementation. The internals
of <code>Prime</code> are not stable, should not be relied upon not to
change, and the output is now intentionally non-deterministic with respect
to the input stream.
</p>
</dd>
</dl><!-- crypto/rand -->
@ -364,6 +406,19 @@ as well as support for rendering them to HTML, Markdown, and text.
<code>CreateCertificate</code> no longer accepts negative serial numbers.
</p>
<p><!-- CL 399827 -->
<code>CreateCertificate</code> will not emit an empty SEQUENCE anymore
when the produced certificate has no extensions.
</p>
<p><!-- CL 396774 -->
Removal of the <code>x509sha1=1</code> <code>GODEBUG</code> option,
originally planned for Go 1.19, has been rescheduled to a future release.
Applications using it should work on migrating. Practical attacks against
SHA-1 have been demonstrated since 2017 and publicly trusted Certificate
Authorities have not issued SHA-1 certificates since 2015.
</p>
<p><!-- CL 383215 -->
<a href="/pkg/crypto/x509/#ParseCertificate"><code>ParseCertificate</code></a>
and <a href="/pkg/crypto/x509/#ParseCertificateRequest"><code>ParseCertificateRequest</code></a>
@ -373,7 +428,7 @@ as well as support for rendering them to HTML, Markdown, and text.
<p><!-- https://go.dev/issue/46057 --><!-- https://go.dev/issue/35044 --><!-- CL 398237 --><!-- CL 400175 --><!-- CL 388915 -->
The new <a href="/pkg/crypto/x509/#CertPool.Clone"><code>CertPool.Clone</code></a>
and <a href="/pkg/crypto/x509/#CertPool.Equal"><code>CertPool.Equal</code></a>
methods allow cloning a <code>CertPool</code> and checking the equality of two
methods allow cloning a <code>CertPool</code> and checking the equivalence of two
<code>CertPool</code>s respectively.
</p>
@ -381,25 +436,26 @@ as well as support for rendering them to HTML, Markdown, and text.
The new function <a href="/pkg/crypto/x509/#ParseRevocationList"><code>ParseRevocationList</code></a>
provides a faster, safer to use CRL parser which returns a
<a href="/pkg/crypto/x509/#RevocationList"><code>RevocationList</code></a>.
To support this addition, <code>RevocationList</code> adds new fields
Parsing a CRL also populates the new <code>RevocationList</code> fields
<code>RawIssuer</code>, <code>Signature</code>,
<code>AuthorityKeyId</code>, and <code>Extensions</code>.
<code>AuthorityKeyId</code>, and <code>Extensions</code>, which are ignored by
<a href="/pkg/crypto/x509/#CreateRevocationList"><code>CreateRevocationList</code></a>.
</p><p>
The new method <a href="/pkg/crypto/x509/#RevocationList.CheckSignatureFrom"><code>RevocationList.CheckSignatureFrom</code></a>
checks that the signature on a CRL is a valid signature from a
<a href="/pkg/crypto/x509/#Certificate"><code>Certificate</code></a>.
With the new CRL functionality, the existing functions
<a href="/pkg/crypto/x509/#ParseCRL"><code>ParseCRL</code></a> and
<a href="/pkg/crypto/x509/#ParseDERCRL"><code>ParseDERCRL</code></a> are deprecated.
Additionally the method <a href="/pkg/crypto/x509#Certificate.CheckCRLSignature"><code>Certificate.CheckCRLSignature</code></a>
is deprecated.
</p><p>
The <a href="/pkg/crypto/x509/#ParseCRL"><code>ParseCRL</code></a> and
<a href="/pkg/crypto/x509/#ParseDERCRL"><code>ParseDERCRL</code></a> functions
are now deprecated in favor of <code>ParseRevocationList</code>.
The <a href="/pkg/crypto/x509#Certificate.CheckCRLSignature"><code>Certificate.CheckCRLSignature</code></a>
method is deprecated in favor of <code>RevocationList.CheckSignatureFrom</code>.
</p>
<p><!-- CL 389555 -->
When building paths, <a href="/pkg/crypto/x509/#Certificate.Verify"><code>Certificate.Verify</code></a>
now considers certificates to be equal when the subjects, public keys, and SANs
are all equal. Before, it required byte-for-byte equality.
<p><!-- CL 389555, CL 401115, CL 403554 -->
The path builder of <a href="/pkg/crypto/x509/#Certificate.Verify"><code>Certificate.Verify</code></a>
was overhauled and should now produce better chains and/or be more efficient in complicated scenarios.
Name constraints are now also enforced on non-leaf certificates.
</p>
</dd>
</dl><!-- crypto/x509 -->
@ -415,14 +471,14 @@ as well as support for rendering them to HTML, Markdown, and text.
</dd>
</dl><!-- crypto/x509/pkix -->
<dl id="debug"><dt><a href="/pkg/debug/">debug</a></dt>
<dl id="debug/elf"><dt><a href="/pkg/debug/elf">debug/elf</a></dt>
<dd>
<p><!-- CL 396735 -->
The new <code>EM_LONGARCH</code> and <code>R_LARCH_*</code> constants
support the loong64 port.
</p>
</dd>
</dl><!-- debug -->
</dl><!-- debug/elf -->
<dl id="debug/pe"><dt><a href="/pkg/debug/pe/">debug/pe</a></dt>
<dd>
@ -816,7 +872,8 @@ as well as support for rendering them to HTML, Markdown, and text.
Compared to v2, it is now typically 1.5x to 2x faster, uses half
as much memory, and it supports an unlimited number of
goroutines.
On Linux, the race detector now requires at least glibc version 2.17.
On Linux, the race detector now requires at least glibc version
2.17 and GNU binutils 2.26.
</p>
<p><!-- CL 336549 -->
@ -851,9 +908,9 @@ as well as support for rendering them to HTML, Markdown, and text.
</p>
<p><!-- https://go.dev/issue/50340 --><!-- CL 396514 -->
The new function
<a href="/pkg/sort/#Find">Find</a>
<a href="/pkg/sort/#Find"><code>Find</code></a>
is like
<a href="/pkg/sort/#Search">Search</a>
<a href="/pkg/sort/#Search"><code>Search</code></a>
but often easier to use: it returns an additional boolean reporting whether an equal value was found.
</p>
</dd>
@ -883,7 +940,7 @@ as well as support for rendering them to HTML, Markdown, and text.
</p>
<p><!-- CL 391434 -->
On AIX and Solaris, <code>Getrusage</code> is now defined.
On AIX and Solaris, <a href="/pkg/syscall/#Getrusage"><code>Getrusage</code></a> is now defined.
</p>
</dd>
</dl><!-- syscall -->

View file

@ -20,10 +20,7 @@ import (
)
func testSetgidStress(t *testing.T) {
var N = 1000
if testing.Short() {
N = 50
}
const N = 50
ch := make(chan int, N)
for i := 0; i < N; i++ {
go func() {

View file

@ -307,6 +307,12 @@ func TestIssue52937(t *testing.T) {
goCmd(t, "build", "-buildmode=plugin", "-o", "issue52937.so", "./issue52937/main.go")
}
func TestIssue53989(t *testing.T) {
goCmd(t, "build", "-buildmode=plugin", "-o", "issue53989.so", "./issue53989/plugin.go")
goCmd(t, "build", "-o", "issue53989.exe", "./issue53989/main.go")
run(t, "./issue53989.exe")
}
func TestForkExec(t *testing.T) {
// Issue 38824: importing the plugin package causes it hang in forkExec on darwin.

View file

@ -0,0 +1,32 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Issue 53989: the use of jump table caused a function
// from the plugin jumps in the middle of the function
// to the function with the same name in the main
// executable. As these two functions may be compiled
// differently as plugin needs to be PIC, this causes
// crash.
package main
import (
"plugin"
"testplugin/issue53989/p"
)
func main() {
p.Square(7) // call the function in main executable
p, err := plugin.Open("issue53989.so")
if err != nil {
panic(err)
}
f, err := p.Lookup("Square")
if err != nil {
panic(err)
}
f.(func(int))(7) // call the plugin one
}

View file

@ -0,0 +1,52 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
import (
"fmt"
"runtime"
)
var y int
//go:noinline
func Square(x int) {
var pc0, pc1 [1]uintptr
runtime.Callers(1, pc0[:]) // get PC at entry
// a switch using jump table
switch x {
case 1:
y = 1
case 2:
y = 4
case 3:
y = 9
case 4:
y = 16
case 5:
y = 25
case 6:
y = 36
case 7:
y = 49
case 8:
y = 64
default:
panic("too large")
}
// check PC is in the same function
runtime.Callers(1, pc1[:])
if pc1[0] < pc0[0] || pc1[0] > pc0[0]+1000000 {
fmt.Printf("jump across DSO boundary. pc0=%x, pc1=%x\n", pc0[0], pc1[0])
panic("FAIL")
}
if y != x*x {
fmt.Printf("x=%d y=%d!=%d\n", x, y, x*x)
panic("FAIL")
}
}

View file

@ -0,0 +1,13 @@
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import "testplugin/issue53989/p"
func Square(x int) { // export Square for plugin
p.Square(x)
}
func main() {}

View file

@ -32,8 +32,7 @@ func (r *Reader) Len() int {
// Size returns the original length of the underlying byte slice.
// Size is the number of bytes available for reading via ReadAt.
// The returned value is always the same and is not affected by calls
// to any other method.
// The result is unaffected by any method calls except Reset.
func (r *Reader) Size() int64 { return int64(len(r.s)) }
// Read implements the io.Reader interface.

View file

@ -1653,10 +1653,18 @@ const cStringDef = `
// freed, such as by calling C.free (be sure to include stdlib.h
// if C.free is needed).
func _Cfunc_CString(s string) *_Ctype_char {
if len(s)+1 <= 0 {
panic("string too large")
}
p := _cgo_cmalloc(uint64(len(s)+1))
pp := (*[1<<30]byte)(p)
copy(pp[:], s)
pp[len(s)] = 0
sliceHeader := struct {
p unsafe.Pointer
len int
cap int
}{p, len(s)+1, len(s)+1}
b := *(*[]byte)(unsafe.Pointer(&sliceHeader))
copy(b, s)
b[len(s)] = 0
return (*_Ctype_char)(p)
}
`
@ -1670,8 +1678,13 @@ const cBytesDef = `
// if C.free is needed).
func _Cfunc_CBytes(b []byte) unsafe.Pointer {
p := _cgo_cmalloc(uint64(len(b)))
pp := (*[1<<30]byte)(p)
copy(pp[:], b)
sliceHeader := struct {
p unsafe.Pointer
len int
cap int
}{p, len(b), len(b)}
s := *(*[]byte)(unsafe.Pointer(&sliceHeader))
copy(s, b)
return p
}
`

View file

@ -242,12 +242,31 @@ var featureToOpcodes = map[string][]string{
// go tool objdump doesn't include a [QL] on popcnt instructions, until CL 351889
// native objdump doesn't include [QL] on linux.
"popcnt": {"popcntq", "popcntl", "popcnt"},
"bmi1": {"andnq", "andnl", "andn", "blsiq", "blsil", "blsi", "blsmskq", "blsmskl", "blsmsk", "blsrq", "blsrl", "blsr", "tzcntq", "tzcntl", "tzcnt"},
"bmi2": {"sarxq", "sarxl", "sarx", "shlxq", "shlxl", "shlx", "shrxq", "shrxl", "shrx"},
"sse41": {"roundsd"},
"fma": {"vfmadd231sd"},
"movbe": {"movbeqq", "movbeq", "movbell", "movbel", "movbe"},
"lzcnt": {"lzcntq", "lzcntl", "lzcnt"},
"bmi1": {
"andnq", "andnl", "andn",
"blsiq", "blsil", "blsi",
"blsmskq", "blsmskl", "blsmsk",
"blsrq", "blsrl", "blsr",
"tzcntq", "tzcntl", "tzcnt",
},
"bmi2": {
"sarxq", "sarxl", "sarx",
"shlxq", "shlxl", "shlx",
"shrxq", "shrxl", "shrx",
},
"sse41": {
"roundsd",
"pinsrq", "pinsrl", "pinsrd", "pinsrb", "pinsr",
"pextrq", "pextrl", "pextrd", "pextrb", "pextr",
"pminsb", "pminsd", "pminuw", "pminud", // Note: ub and sw are ok.
"pmaxsb", "pmaxsd", "pmaxuw", "pmaxud",
"pmovzxbw", "pmovzxbd", "pmovzxbq", "pmovzxwd", "pmovzxwq", "pmovzxdq",
"pmovsxbw", "pmovsxbd", "pmovsxbq", "pmovsxwd", "pmovsxwq", "pmovsxdq",
"pblendvb",
},
"fma": {"vfmadd231sd"},
"movbe": {"movbeqq", "movbeq", "movbell", "movbel", "movbe"},
"lzcnt": {"lzcntq", "lzcntl", "lzcnt"},
}
// Test to use POPCNT instruction, if available

View file

@ -623,7 +623,7 @@ func checkFetchBody(nameNode *ir.Name) {
}
}
// getInstantiation gets the instantiantion and dictionary of the function or method nameNode
// getInstantiation gets the instantiation and dictionary of the function or method nameNode
// with the type arguments shapes. If the instantiated function is not already
// cached, then it calls genericSubst to create the new instantiation.
func (g *genInst) getInstantiation(nameNode *ir.Name, shapes []*types.Type, isMeth bool) *instInfo {

View file

@ -1959,5 +1959,6 @@ func logicFlags32(x int32) flagConstant {
func makeJumpTableSym(b *Block) *obj.LSym {
s := base.Ctxt.Lookup(fmt.Sprintf("%s.jump%d", b.Func.fe.LSym(), b.ID))
s.Set(obj.AttrDuplicateOK, true)
s.Set(obj.AttrLocal, true)
return s
}

View file

@ -1507,6 +1507,10 @@ func (s *state) stmt(n ir.Node) {
case ir.OLABEL:
n := n.(*ir.LabelStmt)
sym := n.Label
if sym.IsBlank() {
// Nothing to do because the label isn't targetable. See issue 52278.
break
}
lab := s.label(sym)
// The label might already have a target block via a goto.

View file

@ -1720,7 +1720,7 @@ func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
func raceDetectorSupported(goos, goarch string) bool {
switch goos {
case "linux":
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64" || goarch == "s390x"
case "darwin":
return goarch == "amd64" || goarch == "arm64"
case "freebsd", "netbsd", "openbsd", "windows":

View file

@ -1708,7 +1708,7 @@
// the package's source root (usually $GOPATH) or that consult environment
// variables only match future runs in which the files and environment
// variables are unchanged. A cached test result is treated as executing
// in no time at all,so a successful package test result will be cached and
// in no time at all, so a successful package test result will be cached and
// reused regardless of -timeout setting.
//
// In addition to the build flags, the flags handled by 'go test' itself are:

View file

@ -132,7 +132,7 @@ test caching explicitly is to use -count=1. Tests that open files within
the package's source root (usually $GOPATH) or that consult environment
variables only match future runs in which the files and environment
variables are unchanged. A cached test result is treated as executing
in no time at all,so a successful package test result will be cached and
in no time at all, so a successful package test result will be cached and
reused regardless of -timeout setting.
In addition to the build flags, the flags handled by 'go test' itself are:

View file

@ -19,7 +19,7 @@ var p224MinusOne = new(fiat.P224Element).Sub(
func p224SqrtCandidate(r, x *fiat.P224Element) {
// Since p = 1 mod 4, we can't use the exponentiation by (p + 1) / 4 like
// for the other primes. Instead, implement a variation of TonelliShanks.
// The contant-time implementation is adapted from Thomas Pornin's ecGFp5.
// The constant-time implementation is adapted from Thomas Pornin's ecGFp5.
//
// https://github.com/pornin/ecgfp5/blob/82325b965/rust/src/field.rs#L337-L385

View file

@ -86,7 +86,7 @@ func (s *Sym) ReceiverName() string {
// Find the first dot after pathend (or from the beginning, if there was
// no slash in name).
l := strings.Index(name[pathend:], ".")
// Find the last dot after pathend (or the beginnng).
// Find the last dot after pathend (or the beginning).
r := strings.LastIndex(name[pathend:], ".")
if l == -1 || r == -1 || l == r {
// There is no receiver if we didn't find two distinct dots after pathend.

View file

@ -50,7 +50,7 @@ type sharedMemHeader struct {
// rawInMem is true if the region holds raw bytes, which occurs during
// minimization. If true after the worker fails during minimization, this
// indicates that an unrecoverable error occurred, and the region can be
// used to retrive the raw bytes that caused the error.
// used to retrieve the raw bytes that caused the error.
rawInMem bool
}

View file

@ -8,6 +8,7 @@ package big
import (
"encoding/binary"
"errors"
"fmt"
)
@ -67,6 +68,9 @@ func (z *Float) GobDecode(buf []byte) error {
*z = Float{}
return nil
}
if len(buf) < 6 {
return errors.New("Float.GobDecode: buffer too small")
}
if buf[0] != floatGobVersion {
return fmt.Errorf("Float.GobDecode: encoding version %d not supported", buf[0])
@ -83,6 +87,9 @@ func (z *Float) GobDecode(buf []byte) error {
z.prec = binary.BigEndian.Uint32(buf[2:])
if z.form == finite {
if len(buf) < 10 {
return errors.New("Float.GobDecode: buffer too small for finite form float")
}
z.exp = int32(binary.BigEndian.Uint32(buf[6:]))
z.mant = z.mant.setBytes(buf[10:])
}

View file

@ -137,3 +137,15 @@ func TestFloatJSONEncoding(t *testing.T) {
}
}
}
func TestFloatGobDecodeShortBuffer(t *testing.T) {
for _, tc := range [][]byte{
[]byte{0x1, 0x0, 0x0, 0x0},
[]byte{0x1, 0xfa, 0x0, 0x0, 0x0, 0x0},
} {
err := NewFloat(0).GobDecode(tc)
if err == nil {
t.Error("expected GobDecode to return error for malformed input")
}
}
}

View file

@ -45,12 +45,18 @@ func (z *Rat) GobDecode(buf []byte) error {
*z = Rat{}
return nil
}
if len(buf) < 5 {
return errors.New("Rat.GobDecode: buffer too small")
}
b := buf[0]
if b>>1 != ratGobVersion {
return fmt.Errorf("Rat.GobDecode: encoding version %d not supported", b>>1)
}
const j = 1 + 4
i := j + binary.BigEndian.Uint32(buf[j-4:j])
if len(buf) < int(i) {
return errors.New("Rat.GobDecode: buffer too small")
}
z.a.neg = b&1 != 0
z.a.abs = z.a.abs.setBytes(buf[j:i])
z.b.abs = z.b.abs.setBytes(buf[i:])

View file

@ -123,3 +123,15 @@ func TestRatXMLEncoding(t *testing.T) {
}
}
}
func TestRatGobDecodeShortBuffer(t *testing.T) {
for _, tc := range [][]byte{
[]byte{0x2},
[]byte{0x2, 0x0, 0x0, 0x0, 0xff},
} {
err := NewRat(1, 2).GobDecode(tc)
if err == nil {
t.Error("expected GobDecode to return error for malformed input")
}
}
}

View file

@ -896,7 +896,7 @@ func (c *Client) PostForm(url string, data url.Values) (resp *Response, err erro
// 307 (Temporary Redirect)
// 308 (Permanent Redirect)
//
// # Head is a wrapper around DefaultClient.Head
// Head is a wrapper around DefaultClient.Head.
//
// To make a request with a specified context.Context, use NewRequestWithContext
// and DefaultClient.Do.

View file

@ -215,8 +215,12 @@ func addrPortToSockaddrInet4(ap netip.AddrPort) (syscall.SockaddrInet4, error) {
func addrPortToSockaddrInet6(ap netip.AddrPort) (syscall.SockaddrInet6, error) {
// ipToSockaddrInet6 has special handling here for zero length slices.
// We do not, because netip has no concept of a generic zero IP address.
//
// addr is allowed to be an IPv4 address, because As16 will convert it
// to an IPv4-mapped IPv6 address.
// The error message is kept consistent with ipToSockaddrInet6.
addr := ap.Addr()
if !addr.Is6() {
if !addr.IsValid() {
return syscall.SockaddrInet6{}, &AddrError{Err: "non-IPv6 address", Addr: addr.String()}
}
sa := syscall.SockaddrInet6{

View file

@ -164,6 +164,10 @@ func (c *UDPConn) ReadFrom(b []byte) (int, Addr, error) {
}
// ReadFromUDPAddrPort acts like ReadFrom but returns a netip.AddrPort.
//
// If c is bound to an unspecified address, the returned
// netip.AddrPort's address might be an IPv4-mapped IPv6 address.
// Use netip.Addr.Unmap to get the address without the IPv6 prefix.
func (c *UDPConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) {
if !c.ok() {
return 0, netip.AddrPort{}, syscall.EINVAL

View file

@ -9,6 +9,7 @@ package net
import (
"errors"
"internal/testenv"
"net/netip"
"os"
"reflect"
"runtime"
@ -622,3 +623,45 @@ func TestUDPIPVersionReadMsg(t *testing.T) {
t.Error("returned UDPAddr is not IPv4")
}
}
// TestIPv6WriteMsgUDPAddrPortTargetAddrIPVersion verifies that
// WriteMsgUDPAddrPort accepts IPv4, IPv4-mapped IPv6, and IPv6 target addresses
// on a UDPConn listening on "::".
func TestIPv6WriteMsgUDPAddrPortTargetAddrIPVersion(t *testing.T) {
if !supportsIPv6() {
t.Skip("IPv6 is not supported")
}
switch runtime.GOOS {
case "openbsd":
// OpenBSD's IPv6 sockets are always IPv6-only, according to the man page:
// https://man.openbsd.org/ip6#IPV6_V6ONLY
t.Skipf("skipping on %v", runtime.GOOS)
}
conn, err := ListenUDP("udp", nil)
if err != nil {
t.Fatal(err)
}
defer conn.Close()
daddr4 := netip.AddrPortFrom(netip.MustParseAddr("127.0.0.1"), 12345)
daddr4in6 := netip.AddrPortFrom(netip.MustParseAddr("::ffff:127.0.0.1"), 12345)
daddr6 := netip.AddrPortFrom(netip.MustParseAddr("::1"), 12345)
buf := make([]byte, 8)
_, _, err = conn.WriteMsgUDPAddrPort(buf, nil, daddr4)
if err != nil {
t.Fatal(err)
}
_, _, err = conn.WriteMsgUDPAddrPort(buf, nil, daddr4in6)
if err != nil {
t.Fatal(err)
}
_, _, err = conn.WriteMsgUDPAddrPort(buf, nil, daddr6)
if err != nil {
t.Fatal(err)
}
}

View file

@ -107,8 +107,18 @@ nocgo:
DATA runtime·mainPC+0(SB)/8,$runtime·main<ABIInternal>(SB)
GLOBL runtime·mainPC(SB),RODATA,$8
// Windows ARM64 needs an immediate 0xf000 argument.
// See go.dev/issues/53837.
#define BREAK \
#ifdef GOOS_windows \
BRK $0xf000 \
#else \
BRK \
#endif \
TEXT runtime·breakpoint(SB),NOSPLIT|NOFRAME,$0-0
BRK
BREAK
RET
TEXT runtime·asminit(SB),NOSPLIT|NOFRAME,$0-0
@ -1325,7 +1335,7 @@ TEXT runtime·debugCallV2<ABIInternal>(SB),NOSPLIT|NOFRAME,$0-0
// Set R20 to 8 and invoke BRK. The debugger should get the
// reason a call can't be injected from SP+8 and resume execution.
MOVD $8, R20
BRK
BREAK
JMP restore
good:
@ -1374,7 +1384,7 @@ good:
MOVD $20, R0
MOVD R0, 16(RSP) // length of debugCallFrameTooLarge string
MOVD $8, R20
BRK
BREAK
JMP restore
restore:
@ -1383,7 +1393,7 @@ restore:
// Set R20 to 16 and invoke BRK. The debugger should restore
// all registers except for PC and RSP and resume execution.
MOVD $16, R20
BRK
BREAK
// We must not modify flags after this point.
// Restore pointer-containing registers, which may have been
@ -1414,9 +1424,9 @@ restore:
TEXT NAME(SB),WRAPPER,$MAXSIZE-0; \
NO_LOCAL_POINTERS; \
MOVD $0, R20; \
BRK; \
BREAK; \
MOVD $1, R20; \
BRK; \
BREAK; \
RET
DEBUG_CALL_FN(debugCall32<>, 32)
DEBUG_CALL_FN(debugCall64<>, 64)
@ -1439,7 +1449,7 @@ TEXT runtime·debugCallPanicked(SB),NOSPLIT,$16-16
MOVD val_data+8(FP), R0
MOVD R0, 16(RSP)
MOVD $2, R20
BRK
BREAK
RET
// Note: these functions use a special calling convention to save generated code space.

View file

@ -44,7 +44,9 @@ x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
}
pthread_attr_init(attr);
pthread_attr_getstacksize(attr, &size);
g->stacklo = (uintptr)&size - size + 4096;
g->stacklo = (uintptr)__builtin_frame_address(0) - size + 4096;
if (g->stacklo >= g->stackhi)
fatalf("bad stack bounds: lo=%p hi=%p\n", g->stacklo, g->stackhi);
pthread_attr_destroy(attr);
free(attr);

View file

@ -432,7 +432,7 @@ func atoi32(s string) (int32, bool) {
// - KiB, MiB, GiB, TiB which represent binary IEC/ISO 80000 units, or
// - B, which just represents bytes.
//
// Returns an int64 because that's what its callers want and recieve,
// Returns an int64 because that's what its callers want and receive,
// but the result is always non-negative.
func parseByteCount(s string) (int64, bool) {
// The empty string is not valid.

View file

@ -53,10 +53,10 @@ import "errors"
// verbatim in the input to Parse.
//
// Year: "2006" "06"
// Month: "Jan" "January"
// Textual day of the week: "Mon" "Monday"
// Numeric day of the month: "2" "_2" "02"
// Numeric day of the year: "__2" "002"
// Month: "Jan" "January" "01" "1"
// Day of the week: "Mon" "Monday"
// Day of the month: "2" "_2" "02"
// Day of the year: "__2" "002"
// Hour: "15" "3" "03" (PM or AM)
// Minute: "4" "04"
// Second: "5" "05"

View file

@ -116,6 +116,13 @@ var formatTests = []FormatTest{
{"StampMicro", StampMicro, "Feb 4 21:00:57.012345"},
{"StampNano", StampNano, "Feb 4 21:00:57.012345600"},
{"YearDay", "Jan 2 002 __2 2", "Feb 4 035 35 4"},
{"Year", "2006 6 06 _6 __6 ___6", "2009 6 09 _6 __6 ___6"},
{"Month", "Jan January 1 01 _1", "Feb February 2 02 _2"},
{"DayOfMonth", "2 02 _2 __2", "4 04 4 35"},
{"DayOfWeek", "Mon Monday", "Wed Wednesday"},
{"Hour", "15 3 03 _3", "21 9 09 _9"},
{"Minute", "4 04 _4", "0 00 _0"},
{"Second", "5 05 _5", "57 57 _57"},
}
func TestFormat(t *testing.T) {

View file

@ -189,13 +189,18 @@ type Pointer *ArbitraryType
// For instance, if x is a slice, Sizeof returns the size of the slice
// descriptor, not the size of the memory referenced by the slice.
// For a struct, the size includes any padding introduced by field alignment.
// The return value of Sizeof is a Go constant.
// The return value of Sizeof is a Go constant if the type of the argument x
// does not have variable size.
// (A type has variable size if it is a type parameter or if it is an array
// or struct type with elements of variable size).
func Sizeof(x ArbitraryType) uintptr
// Offsetof returns the offset within the struct of the field represented by x,
// which must be of the form structValue.field. In other words, it returns the
// number of bytes between the start of the struct and the start of the field.
// The return value of Offsetof is a Go constant.
// The return value of Offsetof is a Go constant if the type of the argument x
// does not have variable size.
// (See the description of [Sizeof] for a definition of variable sized types.)
func Offsetof(x ArbitraryType) uintptr
// Alignof takes an expression x of any type and returns the required alignment
@ -206,7 +211,9 @@ func Offsetof(x ArbitraryType) uintptr
// within that struct, then Alignof(s.f) will return the required alignment
// of a field of that type within a struct. This case is the same as the
// value returned by reflect.TypeOf(s.f).FieldAlign().
// The return value of Alignof is a Go constant.
// The return value of Alignof is a Go constant if the type of the argument
// does not have variable size.
// (See the description of [Sizeof] for a definition of variable sized types.)
func Alignof(x ArbitraryType) uintptr
// The function Add adds len to ptr and returns the updated pointer

View file

@ -1,4 +1,4 @@
// compile
// compile -d=ssa/check/on
// Copyright 2022 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -58,7 +58,7 @@ type envVars struct {
}
var env = func() (res envVars) {
cmd := exec.Command("go", "env", "-json")
cmd := exec.Command(goTool(), "env", "-json")
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal("StdoutPipe:", err)
@ -710,6 +710,22 @@ func (t *test) run() {
if tempDirIsGOPATH {
cmd.Env = append(cmd.Env, "GOPATH="+t.tempDir)
}
// Put the bin directory of the GOROOT that built this program
// first in the path. This ensures that tests that use the "go"
// tool use the same one that built this program. This ensures
// that if you do "../bin/go run run.go" in this directory, all
// the tests that start subprocesses that "go tool compile" or
// whatever, use ../bin/go as their go tool, not whatever happens
// to be first in the user's path.
path := os.Getenv("PATH")
newdir := filepath.Join(runtime.GOROOT(), "bin")
if path != "" {
path = newdir + string(filepath.ListSeparator) + path
} else {
path = newdir
}
cmd.Env = append(cmd.Env, "PATH="+path)
cmd.Env = append(cmd.Env, runenv...)
var err error