Skip to content

Commit

Permalink
Fix sentry debug regex pattern
Browse files Browse the repository at this point in the history
that contained two errors leading to truncated data.
1. When the text is specified greedy, multiple debug messages lead to the payload being in the debug text.
2. When not matching also whitespace-characters, the after data is truncated on a newline.
  • Loading branch information
mpass99 authored and MrSerth committed Sep 10, 2024
1 parent e89d2e3 commit ca655a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/nomad/sentry_debug_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var (
timeDebugMessageFormatEnd = `%s; ec=$?; ` + timeDebugMessageFormat + ` && exit $ec`

timeDebugMessagePattern = regexp.MustCompile(
`(?P<before>[\S\s]*?)\x1EPoseidon (?P<text>[^\x1E]+) (?P<time>\d{13})\x1E(?P<after>.*)`)
`(?P<before>[\S\s]*?)\x1EPoseidon (?P<text>[^\x1E]+?) (?P<time>\d{13})\x1E(?P<after>[\S\s]*)`)
timeDebugMessagePatternStart = regexp.MustCompile(`\x1EPoseidon`)
)

Expand Down
13 changes: 13 additions & 0 deletions internal/nomad/sentry_debug_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ func (s *MainTestSuite) TestSentryDebugWriter_WriteComposed() {
s.Contains(buf.String(), "Hello World!")
}

func (s *MainTestSuite) TestSentryDebugWriter_regression_issue_678() {
buf := &bytes.Buffer{}
debugWriter := NewSentryDebugWriter(s.TestCtx, buf)

innerData := "HOSTNAME=4bf0a8e5dbe4\r\nLANGUAGE=en_US.UTF-8\r\nJAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64\r\nJUNIT=/usr/java/lib/junit-4.13.2.jar\r\nPWD=/workspace\r\n_=/usr/bin/env\r\nHOME=/workspace\r\nLANG=en_US.UTF-8\r\nCOLUMNS=10000\r\nTERM=ansi\r\nUSER=user\r\nSHLVL=2\r\nANTLR=/usr/java/lib/antlr-4.5.3-complete.jar\r\nCODEOCEAN=true\r\nCLASSPATH=.:/usr/java/lib/hamcrest-3.0.jar:/usr/java/lib/junit-4.13.2.jar:/usr/java/lib/antlr-4.5.3-complete.jar:/usr/java/lib/antlr-java8.jar\r\nHAMCREST=/usr/java/lib/hamcrest-3.0.jar\r\nLC_ALL=en_US.UTF-8\r\nPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\r\nANTLR_JAVA8=/usr/java/lib/antlr-java8.jar\r\nUID=1001\r\nDEBIAN_FRONTEND=teletype\r\n" //nolint:lll // regression payload
data := "\x1ePoseidon env 1725462286085\x1e" + innerData + "\x1ePoseidon exit 0 1725462286087\x1e"
count, err := debugWriter.Write([]byte(data))

s.Require().NoError(err)
s.Equal(len(data), count)
s.Equal(innerData, buf.String())
}

func (s *MainTestSuite) TestSentryDebugWriter_Close() {
buf := &bytes.Buffer{}
w := NewSentryDebugWriter(s.TestCtx, buf)
Expand Down

0 comments on commit ca655a8

Please sign in to comment.