Skip to content

Commit 04d67b9

Browse files
committed
Merge tag 'go1.18.3' into tailscale.go1.18
2 parents e6c7599 + 4068be5 commit 04d67b9

File tree

26 files changed

+246
-57
lines changed

26 files changed

+246
-57
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
go1.18.2
1+
go1.18.3

misc/cgo/testsanitizers/testdata/tsan11.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static void register_handler(int signo) {
4545
import "C"
4646

4747
func main() {
48-
ch := make(chan os.Signal)
48+
ch := make(chan os.Signal, 1)
4949
signal.Notify(ch, syscall.SIGUSR2)
5050

5151
C.register_handler(C.int(syscall.SIGUSR1))

misc/cgo/testsanitizers/testdata/tsan12.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
import "C"
2323

2424
func main() {
25-
ch := make(chan os.Signal)
25+
ch := make(chan os.Signal, 1)
2626
signal.Notify(ch, syscall.SIGUSR1)
2727

2828
if err := exec.Command("true").Run(); err != nil {

src/cmd/compile/internal/typecheck/crawler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
234234
for i, t1 := range t.RParams() {
235235
shapes[i] = Shapify(t1, i, baseType.RParams()[i])
236236
}
237-
for j := range t.Methods().Slice() {
237+
for j, tmethod := range t.Methods().Slice() {
238238
baseNname := baseType.Methods().Slice()[j].Nname.(*ir.Name)
239239
dictsym := MakeDictSym(baseNname.Sym(), t.RParams(), true)
240240
if dictsym.Def == nil {
@@ -255,6 +255,8 @@ func (p *crawler) checkForFullyInst(t *types.Type) {
255255
ImportedBody(methNode.Func)
256256
methNode.Func.SetExportInline(true)
257257
}
258+
// Make sure that any associated types are also exported. (See #52279)
259+
p.checkForFullyInst(tmethod.Type)
258260
}
259261
}
260262

src/cmd/compile/internal/typecheck/iexport.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2284,7 +2284,7 @@ func (w *exportWriter) localIdent(s *types.Sym) {
22842284
return
22852285
}
22862286

2287-
if i := strings.LastIndex(name, "."); i >= 0 && !strings.HasPrefix(name, LocalDictName) {
2287+
if i := strings.LastIndex(name, "."); i >= 0 && !strings.HasPrefix(name, LocalDictName) && !strings.HasPrefix(name, ".rcvr") {
22882288
base.Fatalf("unexpected dot in identifier: %v", name)
22892289
}
22902290

src/cmd/compile/internal/typecheck/stmt.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,23 @@ func assign(stmt ir.Node, lhs, rhs []ir.Node) {
127127

128128
checkLHS := func(i int, typ *types.Type) {
129129
lhs[i] = Resolve(lhs[i])
130-
if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Name().Ntype == nil {
131-
if typ.Kind() != types.TNIL {
130+
if base.Flag.G != 0 || base.Debug.Unified != 0 {
131+
// New logic added in CL 403837 for Go 1.19, which only has -G=3 and unified IR.
132+
if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Type() == nil {
133+
base.Assertf(typ.Kind() == types.TNIL, "unexpected untyped nil")
132134
n.SetType(defaultType(typ))
133-
} else {
134-
base.Errorf("use of untyped nil")
135+
}
136+
} else {
137+
// Original logic from Go 1.18, which is still needed for -G=0.
138+
if n := lhs[i]; typ != nil && ir.DeclaredBy(n, stmt) && n.Name().Ntype == nil {
139+
if typ.Kind() != types.TNIL {
140+
n.SetType(defaultType(typ))
141+
} else {
142+
base.Errorf("use of untyped nil")
143+
}
135144
}
136145
}
146+
137147
if lhs[i].Typecheck() == 0 {
138148
lhs[i] = AssignExpr(lhs[i])
139149
}

src/crypto/rand/rand.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,21 @@ var Reader io.Reader
2424
func Read(b []byte) (n int, err error) {
2525
return io.ReadFull(Reader, b)
2626
}
27+
28+
// batched returns a function that calls f to populate a []byte by chunking it
29+
// into subslices of, at most, readMax bytes.
30+
func batched(f func([]byte) error, readMax int) func([]byte) error {
31+
return func(out []byte) error {
32+
for len(out) > 0 {
33+
read := len(out)
34+
if read > readMax {
35+
read = readMax
36+
}
37+
if err := f(out[:read]); err != nil {
38+
return err
39+
}
40+
out = out[read:]
41+
}
42+
return nil
43+
}
44+
}

src/crypto/rand/rand_batched.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package rand
88

99
import (
10+
"errors"
1011
"internal/syscall/unix"
1112
)
1213

@@ -15,28 +16,17 @@ func init() {
1516
altGetRandom = batched(getRandomBatch, maxGetRandomRead)
1617
}
1718

18-
// batched returns a function that calls f to populate a []byte by chunking it
19-
// into subslices of, at most, readMax bytes.
20-
func batched(f func([]byte) bool, readMax int) func([]byte) bool {
21-
return func(buf []byte) bool {
22-
for len(buf) > readMax {
23-
if !f(buf[:readMax]) {
24-
return false
25-
}
26-
buf = buf[readMax:]
27-
}
28-
return len(buf) == 0 || f(buf)
29-
}
30-
}
31-
3219
// If the kernel is too old to support the getrandom syscall(),
3320
// unix.GetRandom will immediately return ENOSYS and we will then fall back to
3421
// reading from /dev/urandom in rand_unix.go. unix.GetRandom caches the ENOSYS
3522
// result so we only suffer the syscall overhead once in this case.
3623
// If the kernel supports the getrandom() syscall, unix.GetRandom will block
3724
// until the kernel has sufficient randomness (as we don't use GRND_NONBLOCK).
3825
// In this case, unix.GetRandom will not return an error.
39-
func getRandomBatch(p []byte) (ok bool) {
26+
func getRandomBatch(p []byte) (err error) {
4027
n, err := unix.GetRandom(p, 0)
41-
return n == len(p) && err == nil
28+
if n != len(p) {
29+
return errors.New("short read")
30+
}
31+
return err
4232
}

src/crypto/rand/rand_batched_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ package rand
88

99
import (
1010
"bytes"
11+
"errors"
1112
"testing"
1213
)
1314

1415
func TestBatched(t *testing.T) {
15-
fillBatched := batched(func(p []byte) bool {
16+
fillBatched := batched(func(p []byte) error {
1617
for i := range p {
1718
p[i] = byte(i)
1819
}
19-
return true
20+
return nil
2021
}, 5)
2122

2223
p := make([]byte, 13)
23-
if !fillBatched(p) {
24-
t.Fatal("batched function returned false")
24+
if err := fillBatched(p); err != nil {
25+
t.Fatalf("batched function returned error: %s", err)
2526
}
2627
expected := []byte{0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2}
2728
if !bytes.Equal(expected, p) {
@@ -30,15 +31,15 @@ func TestBatched(t *testing.T) {
3031
}
3132

3233
func TestBatchedError(t *testing.T) {
33-
b := batched(func(p []byte) bool { return false }, 5)
34-
if b(make([]byte, 13)) {
35-
t.Fatal("batched function should have returned false")
34+
b := batched(func(p []byte) error { return errors.New("") }, 5)
35+
if b(make([]byte, 13)) == nil {
36+
t.Fatal("batched function should have returned error")
3637
}
3738
}
3839

3940
func TestBatchedEmpty(t *testing.T) {
40-
b := batched(func(p []byte) bool { return false }, 5)
41-
if !b(make([]byte, 0)) {
42-
t.Fatal("empty slice should always return true")
41+
b := batched(func(p []byte) error { return errors.New("") }, 5)
42+
if err := b(make([]byte, 0)); err != nil {
43+
t.Fatalf("empty slice should always return nil: %s", err)
4344
}
4445
}

src/crypto/rand/rand_getentropy.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func init() {
1414
altGetRandom = getEntropy
1515
}
1616

17-
func getEntropy(p []byte) (ok bool) {
17+
func getEntropy(p []byte) error {
1818
// getentropy(2) returns a maximum of 256 bytes per call
1919
for i := 0; i < len(p); i += 256 {
2020
end := i + 256
@@ -23,8 +23,8 @@ func getEntropy(p []byte) (ok bool) {
2323
}
2424
err := unix.GetEntropy(p[i:end])
2525
if err != nil {
26-
return false
26+
return err
2727
}
2828
}
29-
return true
29+
return nil
3030
}

src/crypto/rand/rand_unix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type devReader struct {
4545

4646
// altGetRandom if non-nil specifies an OS-specific function to get
4747
// urandom-style randomness.
48-
var altGetRandom func([]byte) (ok bool)
48+
var altGetRandom func([]byte) (err error)
4949

5050
func warnBlocked() {
5151
println("crypto/rand: blocked for 60 seconds waiting to read random data from the kernel")
@@ -58,7 +58,7 @@ func (r *devReader) Read(b []byte) (n int, err error) {
5858
t := time.AfterFunc(60*time.Second, warnBlocked)
5959
defer t.Stop()
6060
}
61-
if altGetRandom != nil && r.name == urandomDevice && altGetRandom(b) {
61+
if altGetRandom != nil && r.name == urandomDevice && altGetRandom(b) == nil {
6262
return len(b), nil
6363
}
6464
r.mu.Lock()

src/crypto/rand/rand_windows.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,18 @@ package rand
99

1010
import (
1111
"internal/syscall/windows"
12-
"os"
1312
)
1413

1514
func init() { Reader = &rngReader{} }
1615

1716
type rngReader struct{}
1817

1918
func (r *rngReader) Read(b []byte) (n int, err error) {
20-
// RtlGenRandom only accepts 2**32-1 bytes at a time, so truncate.
21-
inputLen := uint32(len(b))
22-
23-
if inputLen == 0 {
24-
return 0, nil
25-
}
26-
27-
err = windows.RtlGenRandom(b)
28-
if err != nil {
29-
return 0, os.NewSyscallError("RtlGenRandom", err)
19+
// RtlGenRandom only returns 1<<32-1 bytes at a time. We only read at
20+
// most 1<<31-1 bytes at a time so that this works the same on 32-bit
21+
// and 64-bit systems.
22+
if err := batched(windows.RtlGenRandom, 1<<31-1)(b); err != nil {
23+
return 0, err
3024
}
31-
return int(inputLen), nil
25+
return len(b), nil
3226
}

src/crypto/tls/conn.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Conn struct {
3232

3333
// handshakeStatus is 1 if the connection is currently transferring
3434
// application data (i.e. is not currently processing a handshake).
35+
// handshakeStatus == 1 implies handshakeErr == nil.
3536
// This field is only to be accessed with sync/atomic.
3637
handshakeStatus uint32
3738
// constant after handshake; protected by handshakeMutex
@@ -1403,6 +1404,13 @@ func (c *Conn) HandshakeContext(ctx context.Context) error {
14031404
}
14041405

14051406
func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
1407+
// Fast sync/atomic-based exit if there is no handshake in flight and the
1408+
// last one succeeded without an error. Avoids the expensive context setup
1409+
// and mutex for most Read and Write calls.
1410+
if c.handshakeComplete() {
1411+
return nil
1412+
}
1413+
14061414
handshakeCtx, cancel := context.WithCancel(ctx)
14071415
// Note: defer this before starting the "interrupter" goroutine
14081416
// so that we can tell the difference between the input being canceled and
@@ -1461,6 +1469,9 @@ func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
14611469
if c.handshakeErr == nil && !c.handshakeComplete() {
14621470
c.handshakeErr = errors.New("tls: internal error: handshake should have had a result")
14631471
}
1472+
if c.handshakeErr != nil && c.handshakeComplete() {
1473+
panic("tls: internal error: handshake returned an error but is marked successful")
1474+
}
14641475

14651476
return c.handshakeErr
14661477
}

src/crypto/tls/handshake_server_tls13.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"crypto"
1111
"crypto/hmac"
1212
"crypto/rsa"
13+
"encoding/binary"
1314
"errors"
1415
"hash"
1516
"io"
@@ -741,6 +742,19 @@ func (hs *serverHandshakeStateTLS13) sendSessionTickets() error {
741742
}
742743
m.lifetime = uint32(maxSessionTicketLifetime / time.Second)
743744

745+
// ticket_age_add is a random 32-bit value. See RFC 8446, section 4.6.1
746+
// The value is not stored anywhere; we never need to check the ticket age
747+
// because 0-RTT is not supported.
748+
ageAdd := make([]byte, 4)
749+
_, err = hs.c.config.rand().Read(ageAdd)
750+
if err != nil {
751+
return err
752+
}
753+
m.ageAdd = binary.LittleEndian.Uint32(ageAdd)
754+
755+
// ticket_nonce, which must be unique per connection, is always left at
756+
// zero because we only ever send one ticket per connection.
757+
744758
if _, err := c.writeRecord(recordTypeHandshake, m.marshal()); err != nil {
745759
return err
746760
}

src/os/exec/exec.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,9 @@ func lookExtensions(path, dir string) (string, error) {
374374
// The Wait method will return the exit code and release associated resources
375375
// once the command exits.
376376
func (c *Cmd) Start() error {
377+
if c.Path == "" && c.lookPathErr == nil {
378+
c.lookPathErr = errors.New("exec: no command")
379+
}
377380
if c.lookPathErr != nil {
378381
c.closeDescriptors(c.closeAfterStart)
379382
c.closeDescriptors(c.closeAfterWait)

src/os/exec/exec_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,3 +1081,11 @@ func TestChildCriticalEnv(t *testing.T) {
10811081
t.Error("no SYSTEMROOT found")
10821082
}
10831083
}
1084+
1085+
func TestNoPath(t *testing.T) {
1086+
err := new(exec.Cmd).Start()
1087+
want := "exec: no command"
1088+
if err == nil || err.Error() != want {
1089+
t.Errorf("new(Cmd).Start() = %v, want %q", err, want)
1090+
}
1091+
}

src/path/filepath/path.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,21 @@ func Clean(path string) string {
117117
case os.IsPathSeparator(path[r]):
118118
// empty path element
119119
r++
120-
case path[r] == '.' && (r+1 == n || os.IsPathSeparator(path[r+1])):
120+
case path[r] == '.' && r+1 == n:
121121
// . element
122122
r++
123+
case path[r] == '.' && os.IsPathSeparator(path[r+1]):
124+
// ./ element
125+
r++
126+
127+
for r < len(path) && os.IsPathSeparator(path[r]) {
128+
r++
129+
}
130+
if out.w == 0 && volumeNameLen(path[r:]) > 0 {
131+
// When joining prefix "." and an absolute path on Windows,
132+
// the prefix should not be removed.
133+
out.append('.')
134+
}
123135
case path[r] == '.' && path[r+1] == '.' && (r+2 == n || os.IsPathSeparator(path[r+2])):
124136
// .. element: remove to last separator
125137
r += 2

src/path/filepath/path_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ var wincleantests = []PathTest{
9393
{`//host/share/foo/../baz`, `\\host\share\baz`},
9494
{`\\a\b\..\c`, `\\a\b\c`},
9595
{`\\a\b`, `\\a\b`},
96+
{`.\c:`, `.\c:`},
97+
{`.\c:\foo`, `.\c:\foo`},
98+
{`.\c:foo`, `.\c:foo`},
9699
}
97100

98101
func TestClean(t *testing.T) {

0 commit comments

Comments
 (0)