summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-11-13 01:53:47 +0000
committergVisor bot <gvisor-bot@google.com>2020-11-13 01:53:47 +0000
commitefaa2c8edb6d1b0f279d2e323075a7235eedc156 (patch)
tree6d70460d8b0e607866320b76e435f230f2421937 /pkg
parent988c78b1b7811f6b1e864d9fd6f1e869c43acd11 (diff)
parentd700ba22abb9e5f29749cc3843991c31dc00384d (diff)
Merge release-20201030.0-77-gd700ba22a (automated)
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/header/ipv4.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/pkg/tcpip/header/ipv4.go b/pkg/tcpip/header/ipv4.go
index 7e32b31b4..3d465e28a 100644
--- a/pkg/tcpip/header/ipv4.go
+++ b/pkg/tcpip/header/ipv4.go
@@ -374,8 +374,14 @@ func (b IPv4) Encode(i *IPv4Fields) {
if hdrLen > len(b) {
panic(fmt.Sprintf("encode received %d bytes, wanted >= %d", len(b), hdrLen))
}
- if aLen != copy(b[options:], i.Options) {
- _ = copy(b[options+len(i.Options):options+aLen], []byte{0, 0, 0, 0})
+ opts := b[options:]
+ // This avoids bounds checks on the next line(s) which would happen even
+ // if there's no work to do.
+ if n := copy(opts, i.Options); n != aLen {
+ padding := opts[n:][:aLen-n]
+ for i := range padding {
+ padding[i] = 0
+ }
}
}
b.SetHeaderLength(uint8(hdrLen))