Skip to content

Commit f86edd6

Browse files
committed
add int size checks
1 parent f630435 commit f86edd6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/types/tls/tls.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"bytes"
2323
"encoding/binary"
2424
"fmt"
25+
"log"
26+
"math"
2527
"reflect"
2628
"strconv"
2729
"strings"
@@ -295,6 +297,9 @@ func readVarUint(data []byte, info *fieldInfo) (uint64, error) {
295297
if info == nil || !info.countSet {
296298
return 0, structuralError{info.fieldName(), "no field size information available"}
297299
}
300+
if info.count > math.MaxInt {
301+
log.Printf("info.count=%d int would overflow", info.count)
302+
}
298303
if len(data) < int(info.count) {
299304
return 0, syntaxError{info.fieldName(), "truncated variable-length integer"}
300305
}
@@ -365,6 +370,9 @@ func parseField(v reflect.Value, data []byte, initOffset int, info *fieldInfo) (
365370
return offset, err
366371
}
367372
v.SetUint(val)
373+
if info.count > math.MaxInt {
374+
log.Printf("info.count=%d int would overflow", info.count)
375+
}
368376
offset += int(info.count)
369377
return offset, nil
370378
case reflect.Struct:
@@ -468,7 +476,13 @@ func parseField(v reflect.Value, data []byte, initOffset int, info *fieldInfo) (
468476
if err != nil {
469477
return offset, err
470478
}
479+
if varlen > math.MaxInt {
480+
log.Printf("varlen=%d int would overflow", varlen)
481+
}
471482
datalen := int(varlen)
483+
if info.count > math.MaxInt {
484+
log.Printf("info.count=%d int would overflow", info.count)
485+
}
472486
offset += int(info.count)
473487
rest = rest[info.count:]
474488

0 commit comments

Comments
 (0)