big: prevent errors in Exp in the face of aliasing
R=gri
CC=golang-dev, golang-dev
https://golang.org/cl/1244044
diff --git a/src/pkg/big/nat.go b/src/pkg/big/nat.go
index dc06658..dc2e6be 100755
--- a/src/pkg/big/nat.go
+++ b/src/pkg/big/nat.go
@@ -920,6 +920,11 @@
// If m != nil, expNN calculates x**y mod m. Otherwise it calculates x**y. It
// reuses the storage of z if possible.
func (z nat) expNN(x, y, m nat) nat {
+ if alias(z, x) || alias(z, y) {
+ // We cannot allow in place modification of x or y.
+ z = nil
+ }
+
if len(y) == 0 {
z = z.make(1)
z[0] = 1