Skip to content

Commit 4ea866a

Browse files
committed
[dev.boringcrypto.go1.17] all: merge go1.17.8 into dev.boringcrypto.go1.17
Change-Id: I093903982eb185a2c36b85656c4009ce75d951e3
2 parents 6666adc + 7dd10d4 commit 4ea866a

14 files changed

Lines changed: 393 additions & 54 deletions

File tree

src/cmd/compile/internal/ssa/gen/RISCV64.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,15 @@
250250
(Leq64F ...) => (FLED ...)
251251
(Leq32F ...) => (FLES ...)
252252

253-
(EqPtr x y) => (SEQZ (SUB <x.Type> x y))
253+
(EqPtr x y) => (SEQZ (SUB <typ.Uintptr> x y))
254254
(Eq64 x y) => (SEQZ (SUB <x.Type> x y))
255255
(Eq32 x y) => (SEQZ (SUB <x.Type> (ZeroExt32to64 x) (ZeroExt32to64 y)))
256256
(Eq16 x y) => (SEQZ (SUB <x.Type> (ZeroExt16to64 x) (ZeroExt16to64 y)))
257257
(Eq8 x y) => (SEQZ (SUB <x.Type> (ZeroExt8to64 x) (ZeroExt8to64 y)))
258258
(Eq64F ...) => (FEQD ...)
259259
(Eq32F ...) => (FEQS ...)
260260

261-
(NeqPtr x y) => (SNEZ (SUB <x.Type> x y))
261+
(NeqPtr x y) => (SNEZ (SUB <typ.Uintptr> x y))
262262
(Neq64 x y) => (SNEZ (SUB <x.Type> x y))
263263
(Neq32 x y) => (SNEZ (SUB <x.Type> (ZeroExt32to64 x) (ZeroExt32to64 y)))
264264
(Neq16 x y) => (SNEZ (SUB <x.Type> (ZeroExt16to64 x) (ZeroExt16to64 y)))

src/cmd/compile/internal/ssa/rewriteRISCV64.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/modfetch/coderepo.go

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,46 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
305305
//
306306
// (If the version is +incompatible, then the go.mod file must not exist:
307307
// +incompatible is not an ongoing opt-out from semantic import versioning.)
308-
var canUseIncompatible func() bool
309-
canUseIncompatible = func() bool {
310-
var ok bool
311-
if r.codeDir == "" && r.pathMajor == "" {
308+
incompatibleOk := map[string]bool{}
309+
canUseIncompatible := func(v string) bool {
310+
if r.codeDir != "" || r.pathMajor != "" {
311+
// A non-empty codeDir indicates a module within a subdirectory,
312+
// which necessarily has a go.mod file indicating the module boundary.
313+
// A non-empty pathMajor indicates a module path with a major-version
314+
// suffix, which must match.
315+
return false
316+
}
317+
318+
ok, seen := incompatibleOk[""]
319+
if !seen {
312320
_, errGoMod := r.code.ReadFile(info.Name, "go.mod", codehost.MaxGoMod)
313-
if errGoMod != nil {
314-
ok = true
321+
ok = (errGoMod != nil)
322+
incompatibleOk[""] = ok
323+
}
324+
if !ok {
325+
// A go.mod file exists at the repo root.
326+
return false
327+
}
328+
329+
// Per https://go.dev/issue/51324, previous versions of the 'go' command
330+
// didn't always check for go.mod files in subdirectories, so if the user
331+
// requests a +incompatible version explicitly, we should continue to allow
332+
// it. Otherwise, if vN/go.mod exists, expect that release tags for that
333+
// major version are intended for the vN module.
334+
if v != "" && !strings.HasSuffix(statVers, "+incompatible") {
335+
major := semver.Major(v)
336+
ok, seen = incompatibleOk[major]
337+
if !seen {
338+
_, errGoModSub := r.code.ReadFile(info.Name, path.Join(major, "go.mod"), codehost.MaxGoMod)
339+
ok = (errGoModSub != nil)
340+
incompatibleOk[major] = ok
341+
}
342+
if !ok {
343+
return false
315344
}
316345
}
317-
canUseIncompatible = func() bool { return ok }
318-
return ok
346+
347+
return true
319348
}
320349

321350
// checkCanonical verifies that the canonical version v is compatible with the
@@ -367,7 +396,7 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
367396
base := strings.TrimSuffix(v, "+incompatible")
368397
var errIncompatible error
369398
if !module.MatchPathMajor(base, r.pathMajor) {
370-
if canUseIncompatible() {
399+
if canUseIncompatible(base) {
371400
v = base + "+incompatible"
372401
} else {
373402
if r.pathMajor != "" {
@@ -495,7 +524,7 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
495524
// Save the highest non-retracted canonical tag for the revision.
496525
// If we don't find a better match, we'll use it as the canonical version.
497526
if tagIsCanonical && semver.Compare(highestCanonical, v) < 0 && !isRetracted(v) {
498-
if module.MatchPathMajor(v, r.pathMajor) || canUseIncompatible() {
527+
if module.MatchPathMajor(v, r.pathMajor) || canUseIncompatible(v) {
499528
highestCanonical = v
500529
}
501530
}
@@ -513,12 +542,12 @@ func (r *codeRepo) convert(info *codehost.RevInfo, statVers string) (*RevInfo, e
513542
// retracted versions.
514543
allowedMajor := func(major string) func(v string) bool {
515544
return func(v string) bool {
516-
return (major == "" || semver.Major(v) == major) && !isRetracted(v)
545+
return ((major == "" && canUseIncompatible(v)) || semver.Major(v) == major) && !isRetracted(v)
517546
}
518547
}
519548
if pseudoBase == "" {
520549
var tag string
521-
if r.pseudoMajor != "" || canUseIncompatible() {
550+
if r.pseudoMajor != "" || canUseIncompatible("") {
522551
tag, _ = r.code.RecentTag(info.Name, tagPrefix, allowedMajor(r.pseudoMajor))
523552
} else {
524553
// Allow either v1 or v0, but not incompatible higher versions.

src/cmd/go/internal/modfetch/coderepo_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,54 @@ var codeRepoTests = []codeRepoTest{
458458
rev: "v3.0.0-devel",
459459
err: `resolves to version v0.1.1-0.20220203155313-d59622f6e4d7 (v3.0.0-devel is not a tag)`,
460460
},
461+
462+
// If v2/go.mod exists, then we should prefer to match the "v2"
463+
// pseudo-versions to the nested module, and resolve the module in the parent
464+
// directory to only compatible versions.
465+
//
466+
// However (https://go.dev/issue/51324), previous versions of the 'go' command
467+
// didn't always do so, so if the user explicitly requests a +incompatible
468+
// version (as would be present in an existing go.mod file), we should
469+
// continue to allow it.
470+
{
471+
vcs: "git",
472+
path: "vcs-test.golang.org/git/v2sub.git",
473+
rev: "80beb17a1603",
474+
version: "v0.0.0-20220222205507-80beb17a1603",
475+
name: "80beb17a16036f17a5aedd1bb5bd6d407b3c6dc5",
476+
short: "80beb17a1603",
477+
time: time.Date(2022, 2, 22, 20, 55, 7, 0, time.UTC),
478+
},
479+
{
480+
vcs: "git",
481+
path: "vcs-test.golang.org/git/v2sub.git",
482+
rev: "v2.0.0",
483+
err: `module contains a go.mod file, so module path must match major version ("vcs-test.golang.org/git/v2sub.git/v2")`,
484+
},
485+
{
486+
vcs: "git",
487+
path: "vcs-test.golang.org/git/v2sub.git",
488+
rev: "v2.0.1-0.20220222205507-80beb17a1603",
489+
err: `module contains a go.mod file, so module path must match major version ("vcs-test.golang.org/git/v2sub.git/v2")`,
490+
},
491+
{
492+
vcs: "git",
493+
path: "vcs-test.golang.org/git/v2sub.git",
494+
rev: "v2.0.0+incompatible",
495+
version: "v2.0.0+incompatible",
496+
name: "5fcd3eaeeb391d399f562fd45a50dac9fc34ae8b",
497+
short: "5fcd3eaeeb39",
498+
time: time.Date(2022, 2, 22, 20, 53, 33, 0, time.UTC),
499+
},
500+
{
501+
vcs: "git",
502+
path: "vcs-test.golang.org/git/v2sub.git",
503+
rev: "v2.0.1-0.20220222205507-80beb17a1603+incompatible",
504+
version: "v2.0.1-0.20220222205507-80beb17a1603+incompatible",
505+
name: "80beb17a16036f17a5aedd1bb5bd6d407b3c6dc5",
506+
short: "80beb17a1603",
507+
time: time.Date(2022, 2, 22, 20, 55, 7, 0, time.UTC),
508+
},
461509
}
462510

463511
func TestCodeRepo(t *testing.T) {

src/crypto/x509/parser.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ func isPrintable(b byte) bool {
5151
}
5252

5353
// parseASN1String parses the ASN.1 string types T61String, PrintableString,
54-
// UTF8String, BMPString, and IA5String. This is mostly copied from the
55-
// respective encoding/asn1.parse... methods, rather than just increasing
56-
// the API surface of that package.
54+
// UTF8String, BMPString, IA5String, and NumericString. This is mostly copied
55+
// from the respective encoding/asn1.parse... methods, rather than just
56+
// increasing the API surface of that package.
5757
func parseASN1String(tag cryptobyte_asn1.Tag, value []byte) (string, error) {
5858
switch tag {
5959
case cryptobyte_asn1.T61String:
@@ -93,6 +93,13 @@ func parseASN1String(tag cryptobyte_asn1.Tag, value []byte) (string, error) {
9393
return "", errors.New("invalid IA5String")
9494
}
9595
return s, nil
96+
case cryptobyte_asn1.Tag(asn1.TagNumericString):
97+
for _, b := range value {
98+
if !('0' <= b && b <= '9' || b == ' ') {
99+
return "", errors.New("invalid NumericString")
100+
}
101+
}
102+
return string(value), nil
96103
}
97104
return "", fmt.Errorf("unsupported string type: %v", tag)
98105
}

src/crypto/x509/parser_test.go

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
package x509
5+
6+
import (
7+
"encoding/asn1"
8+
"testing"
9+
10+
cryptobyte_asn1 "golang.org/x/crypto/cryptobyte/asn1"
11+
)
12+
13+
func TestParseASN1String(t *testing.T) {
14+
tests := []struct {
15+
name string
16+
tag cryptobyte_asn1.Tag
17+
value []byte
18+
expected string
19+
expectedErr string
20+
}{
21+
{
22+
name: "T61String",
23+
tag: cryptobyte_asn1.T61String,
24+
value: []byte{80, 81, 82},
25+
expected: string("PQR"),
26+
},
27+
{
28+
name: "PrintableString",
29+
tag: cryptobyte_asn1.PrintableString,
30+
value: []byte{80, 81, 82},
31+
expected: string("PQR"),
32+
},
33+
{
34+
name: "PrintableString (invalid)",
35+
tag: cryptobyte_asn1.PrintableString,
36+
value: []byte{1, 2, 3},
37+
expectedErr: "invalid PrintableString",
38+
},
39+
{
40+
name: "UTF8String",
41+
tag: cryptobyte_asn1.UTF8String,
42+
value: []byte{80, 81, 82},
43+
expected: string("PQR"),
44+
},
45+
{
46+
name: "UTF8String (invalid)",
47+
tag: cryptobyte_asn1.UTF8String,
48+
value: []byte{255},
49+
expectedErr: "invalid UTF-8 string",
50+
},
51+
{
52+
name: "BMPString",
53+
tag: cryptobyte_asn1.Tag(asn1.TagBMPString),
54+
value: []byte{80, 81},
55+
expected: string("偑"),
56+
},
57+
{
58+
name: "BMPString (invalid length)",
59+
tag: cryptobyte_asn1.Tag(asn1.TagBMPString),
60+
value: []byte{255},
61+
expectedErr: "invalid BMPString",
62+
},
63+
{
64+
name: "IA5String",
65+
tag: cryptobyte_asn1.IA5String,
66+
value: []byte{80, 81},
67+
expected: string("PQ"),
68+
},
69+
{
70+
name: "IA5String (invalid)",
71+
tag: cryptobyte_asn1.IA5String,
72+
value: []byte{255},
73+
expectedErr: "invalid IA5String",
74+
},
75+
{
76+
name: "NumericString",
77+
tag: cryptobyte_asn1.Tag(asn1.TagNumericString),
78+
value: []byte{49, 50},
79+
expected: string("12"),
80+
},
81+
{
82+
name: "NumericString (invalid)",
83+
tag: cryptobyte_asn1.Tag(asn1.TagNumericString),
84+
value: []byte{80},
85+
expectedErr: "invalid NumericString",
86+
},
87+
}
88+
89+
for _, tc := range tests {
90+
t.Run(tc.name, func(t *testing.T) {
91+
out, err := parseASN1String(tc.tag, tc.value)
92+
if err != nil && err.Error() != tc.expectedErr {
93+
t.Fatalf("parseASN1String returned unexpected error: got %q, want %q", err, tc.expectedErr)
94+
} else if err == nil && tc.expectedErr != "" {
95+
t.Fatalf("parseASN1String didn't fail, expected: %s", tc.expectedErr)
96+
}
97+
if out != tc.expected {
98+
t.Fatalf("parseASN1String returned unexpected value: got %q, want %q", out, tc.expected)
99+
}
100+
})
101+
}
102+
}

src/net/dnsclient_unix.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const (
3131
// to be used as a useTCP parameter to exchange
3232
useTCPOnly = true
3333
useUDPOrTCP = false
34+
35+
// Maximum DNS packet size.
36+
// Value taken from https://dnsflagday.net/2020/.
37+
maxDNSPacketSize = 1232
3438
)
3539

3640
var (
@@ -83,7 +87,7 @@ func dnsPacketRoundTrip(c Conn, id uint16, query dnsmessage.Question, b []byte)
8387
return dnsmessage.Parser{}, dnsmessage.Header{}, err
8488
}
8589

86-
b = make([]byte, 512) // see RFC 1035
90+
b = make([]byte, maxDNSPacketSize)
8791
for {
8892
n, err := c.Read(b)
8993
if err != nil {

src/net/dnsclient_unix_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ func (f *fakeDNSPacketConn) Close() error {
882882
func TestIgnoreDNSForgeries(t *testing.T) {
883883
c, s := Pipe()
884884
go func() {
885-
b := make([]byte, 512)
885+
b := make([]byte, maxDNSPacketSize)
886886
n, err := s.Read(b)
887887
if err != nil {
888888
t.Error(err)

0 commit comments

Comments
 (0)