I've got runtime error
Oct 26 07:45:18: panic: runtime error: index out of range
Oct 26 07:45:18: goroutine 80639 [running]:
Oct 26 07:45:18: github.com/phalaaxx/milter.(*MilterSession).Process(0xc4210278c0, 0xc4210360a0, 0x0, 0x0, 0x0, 0x0)
Oct 26 07:45:18: /go/src/github.com/phalaaxx/milter/session.go:116 +0x48b
It's caused by bounds check in encoding/binary package.
func (bigEndian) Uint16(b []byte) uint16 {
_ = b[1] // bounds check hint to compiler; see golang.org/issue/14808
return uint16(b[1]) | uint16(b[0])<<8
}
Perhaps it would be better retrun error if msg.Data length less than needed.
...
Hostname := ReadCString(msg.Data)
msg.Data = msg.Data[len(Hostname)+1:]
// get protocol family
ProtocolFamily := msg.Data[0]
msg.Data = msg.Data[1:]
// get port
Port := binary.BigEndian.Uint16(msg.Data)
...
I've got runtime error
It's caused by bounds check in encoding/binary package.
Perhaps it would be better retrun error if msg.Data length less than needed.