]> Cypherpunks repositories - gostls13.git/commitdiff
fmt: catch overflow in width and prec calculations
authorRob Pike <r@golang.org>
Mon, 4 May 2015 18:28:51 +0000 (11:28 -0700)
committerRob Pike <r@golang.org>
Mon, 4 May 2015 19:17:05 +0000 (19:17 +0000)
Fixes #10674.

Change-Id: If3fae3244d87aeaa70815f499105c264394aa7ad
Reviewed-on: https://go-review.googlesource.com/9657
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/fmt/fmt_test.go
src/fmt/print.go

index c06f9a1fcfce422ec5dd4efc95f352cc3e1a5512..5d3357004f85da8894efe3b1c707cbd9c7b79192 100644 (file)
@@ -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
index 8e35a890ec9f2c95740232081aae4fc9bdc1d2ee..9c373145dde76ef1c26d84acea2a342e589d33e0 100644 (file)
@@ -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