]> Cypherpunks repositories - gostls13.git/commitdiff
net: add nil checks to several String methods to avoid panics
authorAndrew Gerrand <adg@golang.org>
Tue, 27 Jul 2010 07:22:22 +0000 (17:22 +1000)
committerAndrew Gerrand <adg@golang.org>
Tue, 27 Jul 2010 07:22:22 +0000 (17:22 +1000)
Fixes #945.

R=r
CC=golang-dev
https://golang.org/cl/1848049

src/pkg/net/dnsclient.go
src/pkg/net/iprawsock.go
src/pkg/net/net.go
src/pkg/net/tcpsock.go
src/pkg/net/udpsock.go

index ea21117e3c2e1047b3e218741b5130b3c81660c6..fe54f6b12a56e8733e9fe70246aae23034806f1b 100644 (file)
@@ -30,6 +30,9 @@ type DNSError struct {
 }
 
 func (e *DNSError) String() string {
+       if e == nil {
+               return "<nil>"
+       }
        s := "lookup " + e.Name
        if e.Server != "" {
                s += " on " + e.Server
index bd8f8080adbf17c591ece6642253be84548f7df1..6b48512e009abf7a0f86399fb5f965b9c9243420 100644 (file)
@@ -30,7 +30,12 @@ type IPAddr struct {
 // Network returns the address's network name, "ip".
 func (a *IPAddr) Network() string { return "ip" }
 
-func (a *IPAddr) String() string { return a.IP.String() }
+func (a *IPAddr) String() string {
+       if a == nil {
+               return "<nil>"
+       }
+       return a.IP.String()
+}
 
 func (a *IPAddr) family() int {
        if a == nil || len(a.IP) <= 4 {
index 04744787008eebf9fb374d6a25f928f5fd64c707..c0c1c3b8ab10f8cf83b6c69bbc032f45235fb7ef 100644 (file)
@@ -129,6 +129,9 @@ type OpError struct {
 }
 
 func (e *OpError) String() string {
+       if e == nil {
+               return "<nil>"
+       }
        s := e.Op
        if e.Net != "" {
                s += " " + e.Net
@@ -164,6 +167,9 @@ type AddrError struct {
 }
 
 func (e *AddrError) String() string {
+       if e == nil {
+               return "<nil>"
+       }
        s := e.Error
        if e.Addr != "" {
                s += " " + e.Addr
index 7a60cd2e7d3db671fdd5651b28c51a5c267a2847..eb846694ba8d9a137a79db571bd1ff71eca94619 100644 (file)
@@ -30,7 +30,12 @@ type TCPAddr struct {
 // Network returns the address's network name, "tcp".
 func (a *TCPAddr) Network() string { return "tcp" }
 
-func (a *TCPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) }
+func (a *TCPAddr) String() string {
+       if a == nil {
+               return "<nil>"
+       }
+       return joinHostPort(a.IP.String(), itoa(a.Port))
+}
 
 func (a *TCPAddr) family() int {
        if a == nil || len(a.IP) <= 4 {
index 6ea0f27531197298173317deb7e80e4ef66a9492..89a074755b08667dd61c1e5a8cdc6aa72abb2001 100644 (file)
@@ -30,7 +30,12 @@ type UDPAddr struct {
 // Network returns the address's network name, "udp".
 func (a *UDPAddr) Network() string { return "udp" }
 
-func (a *UDPAddr) String() string { return joinHostPort(a.IP.String(), itoa(a.Port)) }
+func (a *UDPAddr) String() string {
+       if a == nil {
+               return "<nil>"
+       }
+       return joinHostPort(a.IP.String(), itoa(a.Port))
+}
 
 func (a *UDPAddr) family() int {
        if a == nil || len(a.IP) <= 4 {