diff options
author | Brad Fitzpatrick <bradfitz@golang.org> | 2017-12-11 15:41:24 +0000 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2017-12-11 19:20:05 +0000 |
commit | 3058d38632aea679c96cd41156b2751c97578a2d (patch) | |
tree | deb4ce0fbedf6827d6f58185c3d0dc335dcf7a8b /api | |
parent | 29be20a111d87b41b91e79a59fd3df95062ce91a (diff) | |
download | go-3058d38632aea679c96cd41156b2751c97578a2d.tar.gz go-3058d38632aea679c96cd41156b2751c97578a2d.zip |
strings: fix two Builder bugs allowing mutation of strings, remove ReadFrom
The Builder's ReadFrom method allows the underlying unsafe slice to
escape, and for callers to subsequently modify memory that had been
unsafely converted into an immutable string.
In the original proposal for Builder (#18990), I'd noted there should
be no Read methods:
> There would be no Reset or Bytes or Truncate or Read methods.
> Nothing that could mutate the []byte once it was unsafely converted
> to a string.
And in my prototype (https://golang.org/cl/37767), I handled ReadFrom
properly, but when https://golang.org/cl/74931 arrived, I missed that
it had a ReadFrom method and approved it.
Because we're so close to the Go 1.10 release, just remove the
ReadFrom method rather than think about possible fixes. It has
marginal utility in a Builder anyway.
Also, fix a separate bug that also allowed mutation of a slice's
backing array after it had been converted into a slice by disallowing
copies of the Builder by value.
Updates #18990
Fixes #23083
Fixes #23084
Change-Id: Id1f860f8a4f5f88b32213cf85108ebc609acb95f
Reviewed-on: https://go-review.googlesource.com/83255
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'api')
-rw-r--r-- | api/go1.10.txt | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/api/go1.10.txt b/api/go1.10.txt index c8e504c992..6647ec66dc 100644 --- a/api/go1.10.txt +++ b/api/go1.10.txt @@ -594,7 +594,6 @@ pkg os, method (*SyscallError) Timeout() bool pkg os, var ErrNoDeadline error pkg strings, method (*Builder) Grow(int) pkg strings, method (*Builder) Len() int -pkg strings, method (*Builder) ReadFrom(io.Reader) (int64, error) pkg strings, method (*Builder) Reset() pkg strings, method (*Builder) String() string pkg strings, method (*Builder) Write([]uint8) (int, error) |