Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic in search invalid log #33

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions search_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ func parseLogItem(s string) (*pb.LogMessage, error) {
}
levelLeftBound := strings.Index(s[timeRightBound+1:], "[")
levelRightBound := strings.Index(s[timeRightBound+1:], "]")
if levelLeftBound == -1 || levelRightBound == -1 || levelLeftBound > levelRightBound {
return nil, fmt.Errorf("invalid log string: %s", s)
}
level := ParseLogLevel(s[timeRightBound+1+levelLeftBound+1 : timeRightBound+1+levelRightBound])
item := &pb.LogMessage{
Time: time,
Expand Down
8 changes: 8 additions & 0 deletions search_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`This is an invalid log blablabla][`,
`[2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
})

Expand Down Expand Up @@ -261,6 +262,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -282,6 +284,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -305,6 +308,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
},
},
Expand Down Expand Up @@ -332,6 +336,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
`[2019/08/26 06:19:17.011 -04:00] [TRACE] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:20:14.011 -04:00] [INFO] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:21:14.011 -04:00] [WARN] [printer.go:41] ["Welcome to TiDB."]`,
Expand All @@ -357,6 +362,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 7
Expand All @@ -367,6 +373,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
`[2019/08/26 06:19:15.011 -04:00] [ERROR] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 8
Expand All @@ -376,6 +383,7 @@ func (s *searchLogSuite) TestLogIterator(c *C) {
expect: []string{
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [printer.go:41] ["Welcome to TiDB."]`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] This is an invalid log blablabla][`,
`[2019/08/26 06:19:16.011 -04:00] [DEBUG] [2019/08/26 06:19:17.011 -04:00] ] [INFO] invalid log"]`,
},
},
// 9
Expand Down