aboutsummaryrefslogtreecommitdiff
path: root/src/net/parse.go
diff options
context:
space:
mode:
authorMikio Hara <mikioh.mikioh@gmail.com>2015-07-21 12:51:01 +0900
committerMikio Hara <mikioh.mikioh@gmail.com>2015-11-01 05:28:17 +0000
commitb50b21d3e130cf19de99c2736d038b636dde75c3 (patch)
treeff8bac2a3f5b28546610e6f877fd7a2f7cd38850 /src/net/parse.go
parent3d5163cf4348b5e697dcbf09897a62893876ac3c (diff)
downloadgo-b50b21d3e130cf19de99c2736d038b636dde75c3.tar.xz
net: make Dial, Listen{,Packet} for TCP/UDP with invalid port fail
This change makes Dial, Listen and ListenPacket with invalid port fail whatever GODEBUG=netdns is. Please be informed that cgoLookupPort with an out of range literal number may return either the lower or upper bound value, 0 or 65535, with no error on some platform. Fixes #11715. Change-Id: I43f9c4fb5526d1bf50b97698e0eb39d29fd74c35 Reviewed-on: https://go-review.googlesource.com/12447 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/parse.go')
-rw-r--r--src/net/parse.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/net/parse.go b/src/net/parse.go
index 2c686f5a9f..93cdf8d73f 100644
--- a/src/net/parse.go
+++ b/src/net/parse.go
@@ -118,15 +118,27 @@ const big = 0xFFFFFF
// Returns number, new offset, success.
func dtoi(s string, i0 int) (n int, i int, ok bool) {
n = 0
+ neg := false
+ if len(s) > 0 && s[0] == '-' {
+ neg = true
+ s = s[1:]
+ }
for i = i0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
n = n*10 + int(s[i]-'0')
if n >= big {
- return 0, i, false
+ if neg {
+ return -big, i + 1, false
+ }
+ return big, i, false
}
}
if i == i0 {
return 0, i, false
}
+ if neg {
+ n = -n
+ i++
+ }
return n, i, true
}