summaryrefslogtreecommitdiff
path: root/src/fmt
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2015-05-04 11:28:51 -0700
committerRob Pike <r@golang.org>2015-05-04 19:17:05 +0000
commit660a6825eabcf8529826e25052a8546ac8e1f08f (patch)
treed600683108a13c5d6c3cc38b0f7dd55120f2d60a /src/fmt
parentb86e71f5aae4bd2cd2b1010e1c57909c068178cc (diff)
downloadgo-git-660a6825eabcf8529826e25052a8546ac8e1f08f.tar.gz
fmt: catch overflow in width and prec calculations
Fixes #10674. Change-Id: If3fae3244d87aeaa70815f499105c264394aa7ad Reviewed-on: https://go-review.googlesource.com/9657 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/fmt')
-rw-r--r--src/fmt/fmt_test.go1
-rw-r--r--src/fmt/print.go3
2 files changed, 4 insertions, 0 deletions
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go
index c06f9a1fcf..5d3357004f 100644
--- a/src/fmt/fmt_test.go
+++ b/src/fmt/fmt_test.go
@@ -537,6 +537,7 @@ var fmtTests = []struct {
{"%s", nil, "%!s(<nil>)"},
{"%T", nil, "<nil>"},
{"%-1", 100, "%!(NOVERB)%!(EXTRA int=100)"},
+ {"%017091901790959340919092959340919017929593813360", 0, "%!(NOVERB)%!(EXTRA int=0)"},
// The "<nil>" show up because maps are printed by
// first obtaining a list of keys and then looking up
diff --git a/src/fmt/print.go b/src/fmt/print.go
index 8e35a890ec..9c373145dd 100644
--- a/src/fmt/print.go
+++ b/src/fmt/print.go
@@ -292,6 +292,9 @@ func parsenum(s string, start, end int) (num int, isnum bool, newi int) {
}
for newi = start; newi < end && '0' <= s[newi] && s[newi] <= '9'; newi++ {
num = num*10 + int(s[newi]-'0')
+ if num < 0 {
+ return 0, false, end // Overflow; crazy long number most likely.
+ }
isnum = true
}
return