Skip to content

crypto/tls: Conn.VerifyHostname crashes when len(c.PeerCertificates) == 0 #1114

Description

@rsc
From: Robert <hancock.robert@gmail.com>
To: golang-nuts <golang-nuts@googlegroups.com>

When I attempt a post to a Buzz URL, I get a panic.  Does the error
indicate that you have to somewhere register a public key before
calling http.Post(...)?

uri := "https://www.google.com/accounts/OAuthGetRequestToken";

bodytype := "application/x-www-form-urlencoded"

body := strings.NewReader("scope=https://www.googleapis.com/auth/
buzz&oauth_callback=oob&oauth_timestamp=1284580740&oauth_version=1.0&oauth_signature=q3Aw4ymlgJcuxsaPPKYK/
zF5rF8%3d&oauth_consumer_key=anonymous&oauth_nonce=5577006791947779410&=
oauth_signature_method=HMAC-SHA1")

r, err := http.Post(uri, bodytype, body)

produces - panic: runtime error: index out of range
...
crypto/tls.*Conn=B7VerifyHostname+0x35 /home/rhancock/go/src/pkg/crypto/
tls/conn.go:678
    crypto/tls.*Conn=B7VerifyHostname(0x7f0dce6db000, 0x0, 0x0,
0x7f0dce62ae30, 0x7f0dce6d5900, ...)
...

The function in conn.go is
func (c *Conn) VerifyHostname(host string) os.Error {
    return c.PeerCertificates()[0].VerifyHostname(host)
}

It looks like the error is that c.PeerCertificates is empty.

Details of the stack trace:
--------------------------
panic: runtime error: index out of range

panic PC=3D0x7f0dce62ad40
runtime.panic+0xb2 /home/rhancock/go/src/pkg/runtime/proc.c:1019
    runtime.panic(0x7f0d00000000, 0x406c03)
panicstring+0x69 /home/rhancock/go/src/pkg/runtime/runtime.c:83
    panicstring(0x4e0858, 0x7f0dce6c93f0)
runtime.panicindex+0x25 /home/rhancock/go/src/pkg/runtime/runtime.c:44
    runtime.panicindex()
crypto/tls.*Conn=B7VerifyHostname+0x35 /home/rhancock/go/src/pkg/crypto/
tls/conn.go:678
    crypto/tls.*Conn=B7VerifyHostname(0x7f0dce6db000, 0x0, 0x0,
0x7f0dce62ae30, 0x7f0dce6d5900, ...)
http.send+0x9bf /home/rhancock/go/src/pkg/http/client.go:74
    http.send(0x7f0dce6db000, 0x517bb0, 0x7f0d0000000e, 0x7f0dce6db000,
0x7f0dce6db000, ...)
http.Post+0x251 /home/rhancock/go/src/pkg/http/client.go:173
    http.Post(0x7f0dce63b240, 0x7f0d00000034, 0x0, 0x0, 0x0, ...)
main.main+0x333 /usr/local/src/go-buzz-client/./buzz_login.go:51
    main.main()
mainstart+0xf /home/rhancock/go/src/pkg/runtime/amd64/asm.s:78
    mainstart()
goexit /home/rhancock/go/src/pkg/runtime/proc.c:145

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions