go.crypto/ssh: use binary.BigEndian throughout
A small cleanup. R=agl, gustav.paul CC=golang-dev https://golang.org/cl/6406043
This commit is contained in:
+6
-5
@@ -7,6 +7,7 @@ package ssh
|
|||||||
import (
|
import (
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
@@ -212,8 +213,8 @@ func (c *ClientConn) mainLoop() {
|
|||||||
// malformed data packet
|
// malformed data packet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4])
|
remoteId := binary.BigEndian.Uint32(packet[1:5])
|
||||||
length := uint32(packet[5])<<24 | uint32(packet[6])<<16 | uint32(packet[7])<<8 | uint32(packet[8])
|
length := binary.BigEndian.Uint32(packet[5:9])
|
||||||
packet = packet[9:]
|
packet = packet[9:]
|
||||||
|
|
||||||
if length != uint32(len(packet)) {
|
if length != uint32(len(packet)) {
|
||||||
@@ -229,9 +230,9 @@ func (c *ClientConn) mainLoop() {
|
|||||||
// malformed data packet
|
// malformed data packet
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4])
|
remoteId := binary.BigEndian.Uint32(packet[1:5])
|
||||||
datatype := uint32(packet[5])<<24 | uint32(packet[6])<<16 | uint32(packet[7])<<8 | uint32(packet[8])
|
datatype := binary.BigEndian.Uint32(packet[5:9])
|
||||||
length := uint32(packet[9])<<24 | uint32(packet[10])<<16 | uint32(packet[11])<<8 | uint32(packet[12])
|
length := binary.BigEndian.Uint32(packet[9:13])
|
||||||
packet = packet[13:]
|
packet = packet[13:]
|
||||||
|
|
||||||
if length != uint32(len(packet)) {
|
if length != uint32(len(packet)) {
|
||||||
|
|||||||
+3
-2
@@ -10,6 +10,7 @@ import (
|
|||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
|
"encoding/binary"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
@@ -548,14 +549,14 @@ func (s *ServerConn) Accept() (Channel, error) {
|
|||||||
// malformed data packet
|
// malformed data packet
|
||||||
return nil, ParseError{msgChannelData}
|
return nil, ParseError{msgChannelData}
|
||||||
}
|
}
|
||||||
remoteId := uint32(packet[1])<<24 | uint32(packet[2])<<16 | uint32(packet[3])<<8 | uint32(packet[4])
|
remoteId := binary.BigEndian.Uint32(packet[1:5])
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
c, ok := s.channels[remoteId]
|
c, ok := s.channels[remoteId]
|
||||||
if !ok {
|
if !ok {
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if length := int(packet[5])<<24 | int(packet[6])<<16 | int(packet[7])<<8 | int(packet[8]); length > 0 {
|
if length := binary.BigEndian.Uint32(packet[5:9]); length > 0 {
|
||||||
packet = packet[9:]
|
packet = packet[9:]
|
||||||
c.handleData(packet[:length])
|
c.handleData(packet[:length])
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"crypto"
|
"crypto"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
@@ -90,7 +91,7 @@ func (r *reader) readOnePacket() ([]byte, error) {
|
|||||||
macSize = uint32(r.mac.Size())
|
macSize = uint32(r.mac.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
length := uint32(lengthBytes[0])<<24 | uint32(lengthBytes[1])<<16 | uint32(lengthBytes[2])<<8 | uint32(lengthBytes[3])
|
length := binary.BigEndian.Uint32(lengthBytes[0:4])
|
||||||
paddingLength := uint32(lengthBytes[4])
|
paddingLength := uint32(lengthBytes[4])
|
||||||
|
|
||||||
if length <= paddingLength+1 {
|
if length <= paddingLength+1 {
|
||||||
|
|||||||
Reference in New Issue
Block a user