Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(823)

Delta Between Two Patch Sets: src/pkg/crypto/tls/conn.go

Issue 6497070: code review 6497070: crypto/tls: fix data race on conn.err (Closed)
Left Patch Set: diff -r e6da0262840c https://code.google.com/p/go Created 11 years, 7 months ago
Right Patch Set: diff -r f06edb3fcffe https://go.googlecode.com/hg/ Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/crypto/tls/handshake_client.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // TLS low level connection and record layer 5 // TLS low level connection and record layer
6 6
7 package tls 7 package tls
8 8
9 import ( 9 import (
10 "bytes" 10 "bytes"
(...skipping 26 matching lines...) Expand all
37 // verifiedChains contains the certificate chains that we built, as 37 // verifiedChains contains the certificate chains that we built, as
38 // opposed to the ones presented by the server. 38 // opposed to the ones presented by the server.
39 verifiedChains [][]*x509.Certificate 39 verifiedChains [][]*x509.Certificate
40 // serverName contains the server name indicated by the client, if any. 40 // serverName contains the server name indicated by the client, if any.
41 serverName string 41 serverName string
42 42
43 clientProtocol string 43 clientProtocol string
44 clientProtocolFallback bool 44 clientProtocolFallback bool
45 45
46 // first permanent error 46 // first permanent error
47 » e 47 » connErr
48 48
49 // input/output 49 // input/output
50 in, out halfConn // in.Mutex < out.Mutex 50 in, out halfConn // in.Mutex < out.Mutex
51 rawInput *block // raw input, right off the wire 51 rawInput *block // raw input, right off the wire
52 input *block // application data waiting to be read 52 input *block // application data waiting to be read
53 hand bytes.Buffer // handshake data waiting to be read 53 hand bytes.Buffer // handshake data waiting to be read
54 54
55 tmp [16]byte 55 tmp [16]byte
56 } 56 }
57 57
58 type e struct { 58 type connErr struct {
59 » sync.Mutex 59 » mu sync.Mutex
60 value error 60 value error
61 } 61 }
62 62
63 func (e *e) setError(err error) error { 63 func (e *connErr) setError(err error) error {
64 » e.Mutex.Lock() 64 » e.mu.Lock()
65 » defer e.Mutex.Unlock() 65 » defer e.mu.Unlock()
66 66
67 if e.value == nil { 67 if e.value == nil {
68 e.value = err 68 e.value = err
69 } 69 }
70 return err 70 return err
71 } 71 }
72 72
73 func (e *e) error() error { 73 func (e *connErr) error() error {
74 » e.Mutex.Lock() 74 » e.mu.Lock()
75 » defer e.Mutex.Unlock() 75 » defer e.mu.Unlock()
76 return e.value 76 return e.value
77 } 77 }
78 78
79 // Access to net.Conn methods. 79 // Access to net.Conn methods.
80 // Cannot just embed net.Conn because that would 80 // Cannot just embed net.Conn because that would
81 // export the struct field too. 81 // export the struct field too.
82 82
83 // LocalAddr returns the local network address. 83 // LocalAddr returns the local network address.
84 func (c *Conn) LocalAddr() net.Addr { 84 func (c *Conn) LocalAddr() net.Addr {
85 return c.conn.LocalAddr() 85 return c.conn.LocalAddr()
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
737 } 737 }
738 return m, nil 738 return m, nil
739 } 739 }
740 740
741 // Write writes data to the connection. 741 // Write writes data to the connection.
742 func (c *Conn) Write(b []byte) (int, error) { 742 func (c *Conn) Write(b []byte) (int, error) {
743 if err := c.error(); err != nil { 743 if err := c.error(); err != nil {
744 return 0, err 744 return 0, err
745 } 745 }
746 746
747 » if err := c.setError(c.Handshake()); err != nil { 747 » if err := c.Handshake(); err != nil {
748 » » return 0, err 748 » » return 0, c.setError(err)
749 } 749 }
750 750
751 c.out.Lock() 751 c.out.Lock()
752 defer c.out.Unlock() 752 defer c.out.Unlock()
753 753
754 if !c.handshakeComplete { 754 if !c.handshakeComplete {
755 return 0, alertInternalError 755 return 0, alertInternalError
756 } 756 }
757 757
758 n, err := c.writeRecord(recordTypeApplicationData, b) 758 n, err := c.writeRecord(recordTypeApplicationData, b)
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
856 c.handshakeMutex.Lock() 856 c.handshakeMutex.Lock()
857 defer c.handshakeMutex.Unlock() 857 defer c.handshakeMutex.Unlock()
858 if !c.isClient { 858 if !c.isClient {
859 return errors.New("VerifyHostname called on TLS server connectio n") 859 return errors.New("VerifyHostname called on TLS server connectio n")
860 } 860 }
861 if !c.handshakeComplete { 861 if !c.handshakeComplete {
862 return errors.New("TLS handshake has not yet been performed") 862 return errors.New("TLS handshake has not yet been performed")
863 } 863 }
864 return c.peerCertificates[0].VerifyHostname(host) 864 return c.peerCertificates[0].VerifyHostname(host)
865 } 865 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b