Transport padding (s4) crashed the whole process with "index out of range" in RoutineSequentialSender on the first data packet: InputPacket/InputPackets sized elem.buffer without headroom for the in-buffer right-shift that prepends the random prefix. - send.go: reserve paddings.transport in both injection-path allocLength computations; replace the manual backward byte loop with an overlap-safe copy; defensively grow the buffer (pool-backed) if it still lacks headroom, dropping packets that cannot fit a single WG message instead of overrunning. - receive.go: drop the rxBytes/timers block duplicated by the AWG re-graft (rx accounting was doubled, keepKeyFreshReceiving fired twice per batch). - send.go: swap jmin/jmax when configured inverted (UAPI validates the fields only individually; a swapped pair panicked rand.Int with a non-positive bound on the first handshake). - obf*.go: bound obfuscator length args to [0, MaxMessageSize] (negative panicked slice bounds, huge ones OOMed the handshake). - magic-header.go: widen to int64 before end-start+1 so a full-range header cannot wrap to a zero rand.Int bound. Tests: transport_padding_test.go reproduces the on-device crash byte-for-byte (red on the previous commit, green now) across both injection paths and the tun path; obf_guards_test.go pins the config-value guards.
47 lines
783 B
Go
47 lines
783 B
Go
package device
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"unicode"
|
|
)
|
|
|
|
const chars52 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
func newRandCharObf(val string) (obf, error) {
|
|
length, err := parseObfLen(val)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &randCharObf{
|
|
length: length,
|
|
}, nil
|
|
}
|
|
|
|
type randCharObf struct {
|
|
length int
|
|
}
|
|
|
|
func (o *randCharObf) Obfuscate(dst, src []byte) {
|
|
rand.Read(dst[:o.length])
|
|
for i := range dst[:o.length] {
|
|
dst[i] = chars52[dst[i]%52]
|
|
}
|
|
}
|
|
|
|
func (o *randCharObf) Deobfuscate(dst, src []byte) bool {
|
|
for _, b := range src[:o.length] {
|
|
if !unicode.IsLetter(rune(b)) {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (o *randCharObf) ObfuscatedLen(n int) int {
|
|
return o.length
|
|
}
|
|
|
|
func (o *randCharObf) DeobfuscatedLen(n int) int {
|
|
return 0
|
|
}
|