Skip to content

Commit e815a5d

Browse files
committed
Prevent integer overflow in SentryDebugWriter
1 parent 1bfc194 commit e815a5d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

internal/nomad/sentry_debug_writer.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package nomad
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"io"
9+
"math"
810
"regexp"
911
"strconv"
1012
"time"
@@ -14,6 +16,7 @@ import (
1416
)
1517

1618
var (
19+
ErrDebugMessageIntegerOverflow = errors.New("SentryDebugWriter data too large to process")
1720
// timeDebugMessageFormat is the format of messages that will be converted to debug messages.
1821
timeDebugMessageFormat = `echo -ne "\x1EPoseidon %s $(date +%%s%%3N)\x1E"`
1922
// Format Parameters: 1. Debug Comment, 2. command.
@@ -65,6 +68,9 @@ func (s *SentryDebugWriter) Write(debugData []byte) (n int, err error) {
6568

6669
if s.remaining.Len() > 0 {
6770
n -= s.remaining.Len()
71+
if len(debugData) > (math.MaxInt64 - s.remaining.Len()) {
72+
return 0, ErrDebugMessageIntegerOverflow
73+
}
6874
joinedDebugData := make([]byte, 0, s.remaining.Len()+len(debugData))
6975
joinedDebugData = append(joinedDebugData, s.remaining.Bytes()...)
7076
joinedDebugData = append(joinedDebugData, debugData...)

0 commit comments

Comments
 (0)