Skip to content

Commit 6a34206

Browse files
committed
crypto/tls: fix parsing of SNI extension.
The previous code had a brain fart: it took one of the length prefixes as an element count, not a length. This didn't actually affect anything because the loop stops as soon as it finds a hostname element, and the hostname element is always the first and only element. (No other element types have ever been defined.) This change fixes the parsing in case SNI is ever changed in the future. Fixes #10793. Change-Id: Iafdf3381942bc22b1f33595315c53dc6cc2e9f0f Reviewed-on: https://go-review.googlesource.com/11059 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 71e83b8 commit 6a34206

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/crypto/tls/handshake_messages.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,16 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
367367

368368
switch extension {
369369
case extensionServerName:
370-
if length < 2 {
370+
d := data[:length]
371+
if len(d) < 2 {
371372
return false
372373
}
373-
numNames := int(data[0])<<8 | int(data[1])
374-
d := data[2:]
375-
for i := 0; i < numNames; i++ {
374+
namesLen := int(d[0])<<8 | int(d[1])
375+
d = d[2:]
376+
if len(d) != namesLen {
377+
return false
378+
}
379+
for len(d) > 0 {
376380
if len(d) < 3 {
377381
return false
378382
}
@@ -383,7 +387,7 @@ func (m *clientHelloMsg) unmarshal(data []byte) bool {
383387
return false
384388
}
385389
if nameType == 0 {
386-
m.serverName = string(d[0:nameLen])
390+
m.serverName = string(d[:nameLen])
387391
break
388392
}
389393
d = d[nameLen:]

0 commit comments

Comments
 (0)