| From 8acd01094d9ee17f6e763a61e49a8a808b3a9ddb Mon Sep 17 00:00:00 2001 |
| From: Brad Fitzpatrick <bradfitz@golang.org> |
| Date: Mon, 2 Aug 2021 14:55:51 -0700 |
| Subject: [PATCH 1/3] net/netip: add new IP address package |
| |
| Co-authored-by: Alex Willmer <alex@moreati.org.uk> (GitHub @moreati) |
| Co-authored-by: Alexander Yastrebov <yastrebov.alex@gmail.com> |
| Co-authored-by: David Anderson <dave@natulte.net> (Tailscale CLA) |
| Co-authored-by: David Crawshaw <crawshaw@tailscale.com> (Tailscale CLA) |
| Co-authored-by: Dmytro Shynkevych <dmytro@tailscale.com> (Tailscale CLA) |
| Co-authored-by: Elias Naur <mail@eliasnaur.com> |
| Co-authored-by: Joe Tsai <joetsai@digital-static.net> (Tailscale CLA) |
| Co-authored-by: Jonathan Yu <jawnsy@cpan.org> (GitHub @jawnsy) |
| Co-authored-by: Josh Bleecher Snyder <josharian@gmail.com> (Tailscale CLA) |
| Co-authored-by: Maisem Ali <maisem@tailscale.com> (Tailscale CLA) |
| Co-authored-by: Manuel Mendez (Go AUTHORS mmendez534@...) |
| Co-authored-by: Matt Layher <mdlayher@gmail.com> |
| Co-authored-by: Noah Treuhaft <noah.treuhaft@gmail.com> (GitHub @nwt) |
| Co-authored-by: Stefan Majer <stefan.majer@gmail.com> |
| Co-authored-by: Terin Stock <terinjokes@gmail.com> (Cloudflare CLA) |
| Co-authored-by: Tobias Klauser <tklauser@distanz.ch> |
| |
| Fixes #46518 |
| |
| Change-Id: I0041f9e1115d61fa6e95fcf32b01d9faee708712 |
| Reviewed-on: https://go-review.googlesource.com/c/go/+/339309 |
| Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> |
| TryBot-Result: Go Bot <gobot@golang.org> |
| Reviewed-by: Russ Cox <rsc@golang.org> |
| Trust: Brad Fitzpatrick <bradfitz@golang.org> |
| |
| Dependency Patch #1 |
| |
| Upstream-Status: Backport [https://github.com/golang/go/commit/a59e33224e42d60a97fa720a45e1b74eb6aaa3d0] |
| CVE: CVE-2023-24538 |
| Signed-off-by: Shubham Kulkarni <skulkarni@mvista.com> |
| --- |
| src/internal/godebug/godebug.go | 34 ++++++++++++++++++++++++++++++++++ |
| src/internal/godebug/godebug_test.go | 34 ++++++++++++++++++++++++++++++++++ |
| 2 files changed, 68 insertions(+) |
| create mode 100644 src/internal/godebug/godebug.go |
| create mode 100644 src/internal/godebug/godebug_test.go |
| |
| diff --git a/src/internal/godebug/godebug.go b/src/internal/godebug/godebug.go |
| new file mode 100644 |
| index 0000000..ac434e5 |
| --- /dev/null |
| +++ b/src/internal/godebug/godebug.go |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2021 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 godebug parses the GODEBUG environment variable. |
| +package godebug |
| + |
| +import "os" |
| + |
| +// Get returns the value for the provided GODEBUG key. |
| +func Get(key string) string { |
| + return get(os.Getenv("GODEBUG"), key) |
| +} |
| + |
| +// get returns the value part of key=value in s (a GODEBUG value). |
| +func get(s, key string) string { |
| + for i := 0; i < len(s)-len(key)-1; i++ { |
| + if i > 0 && s[i-1] != ',' { |
| + continue |
| + } |
| + afterKey := s[i+len(key):] |
| + if afterKey[0] != '=' || s[i:i+len(key)] != key { |
| + continue |
| + } |
| + val := afterKey[1:] |
| + for i, b := range val { |
| + if b == ',' { |
| + return val[:i] |
| + } |
| + } |
| + return val |
| + } |
| + return "" |
| +} |
| diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go |
| new file mode 100644 |
| index 0000000..41b9117 |
| --- /dev/null |
| +++ b/src/internal/godebug/godebug_test.go |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2021 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 godebug |
| + |
| +import "testing" |
| + |
| +func TestGet(t *testing.T) { |
| + tests := []struct { |
| + godebug string |
| + key string |
| + want string |
| + }{ |
| + {"", "", ""}, |
| + {"", "foo", ""}, |
| + {"foo=bar", "foo", "bar"}, |
| + {"foo=bar,after=x", "foo", "bar"}, |
| + {"before=x,foo=bar,after=x", "foo", "bar"}, |
| + {"before=x,foo=bar", "foo", "bar"}, |
| + {",,,foo=bar,,,", "foo", "bar"}, |
| + {"foodecoy=wrong,foo=bar", "foo", "bar"}, |
| + {"foo=", "foo", ""}, |
| + {"foo", "foo", ""}, |
| + {",foo", "foo", ""}, |
| + {"foo=bar,baz", "loooooooong", ""}, |
| + } |
| + for _, tt := range tests { |
| + got := get(tt.godebug, tt.key) |
| + if got != tt.want { |
| + t.Errorf("get(%q, %q) = %q; want %q", tt.godebug, tt.key, got, tt.want) |
| + } |
| + } |
| +} |
| -- |
| 2.7.4 |