summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-02-13 16:20:56 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-02-14 18:53:55 +0100
commit9cbcff10dd3e04671d31ab224526f3d22a7ba665 (patch)
tree50cb5fa60a0dfc1e580656f8254ff147a7da8109
parent6ed56ff2dfd57ba47cdf604eb3c455acb553c0df (diff)
send: account for zero mtu
Don't divide by zero.
-rw-r--r--device/send.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/device/send.go b/device/send.go
index 72633be..9e29d77 100644
--- a/device/send.go
+++ b/device/send.go
@@ -515,10 +515,18 @@ func (device *Device) RoutineEncryption() {
// pad content to multiple of 16
mtu := int(atomic.LoadInt32(&device.tun.mtu))
- lastUnit := len(elem.packet) % mtu
- paddedSize := (lastUnit + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
- if paddedSize > mtu {
- paddedSize = mtu
+ var paddedSize int
+ if mtu == 0 {
+ paddedSize = (len(elem.packet) + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
+ } else {
+ lastUnit := len(elem.packet)
+ if lastUnit > mtu {
+ lastUnit %= mtu
+ }
+ paddedSize := (lastUnit + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
+ if paddedSize > mtu {
+ paddedSize = mtu
+ }
}
for i := len(elem.packet); i < paddedSize; i++ {
elem.packet = append(elem.packet, 0)