Skip to content

Commit

Permalink
Prevent integer overflow in SentryDebugWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSerth committed Feb 16, 2025
1 parent 1bfc194 commit e815a5d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/nomad/sentry_debug_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package nomad
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"math"
"regexp"
"strconv"
"time"
Expand All @@ -14,6 +16,7 @@ import (
)

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

if s.remaining.Len() > 0 {
n -= s.remaining.Len()
if len(debugData) > (math.MaxInt64 - s.remaining.Len()) {
return 0, ErrDebugMessageIntegerOverflow
}
joinedDebugData := make([]byte, 0, s.remaining.Len()+len(debugData))
joinedDebugData = append(joinedDebugData, s.remaining.Bytes()...)
joinedDebugData = append(joinedDebugData, debugData...)
Expand Down

0 comments on commit e815a5d

Please sign in to comment.