Skip to content

Commit

Permalink
[TT-7127] Fix goplugin invalid memory address or nil pointer derefere…
Browse files Browse the repository at this point in the history
…nce (#5589)

https://tyktech.atlassian.net/browse/TT-7127

Closes #4198 #4197

Signed-off-by: Chenyang Yan <[email protected]>
Co-authored-by: Chenyang Yan <[email protected]>
(cherry picked from commit 921bdc5)
  • Loading branch information
titpetric authored and Tyk Bot committed Oct 5, 2023
1 parent 77a1362 commit 2026c80
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gateway/mw_go_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ func (m *GoPluginMiddleware) goPluginFromRequest(r *http.Request) (*GoPluginMidd
return perPathPerMethodGoPlugin.(*GoPluginMiddleware), found
}
func (m *GoPluginMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Request, conf interface{}) (err error, respCode int) {
// if a Go plugin is found for this path, override the base handler and logger:
logger := m.logger
handler := m.handler
successHandler := m.successHandler

if !m.APILevel {
// if a Go plugin is found for this path, override the base handler and logger
if pluginMw, found := m.goPluginFromRequest(r); found {
logger = pluginMw.logger
handler = pluginMw.handler
successHandler = &SuccessHandler{BaseMiddleware: m.BaseMiddleware}
} else {
return nil, http.StatusOK // next middleware
}
Expand Down Expand Up @@ -226,7 +229,11 @@ func (m *GoPluginMiddleware) ProcessRequest(w http.ResponseWriter, r *http.Reque
m.logger.WithError(err).Error("Failed to process request with Go-plugin middleware func")
default:
// record 2XX to analytics
<<<<<<< HEAD

Check failure on line 232 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 6

syntax error: unexpected <<, expecting case or default or }

Check failure on line 232 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 5

syntax error: unexpected <<, expecting case or default or }
m.successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))

Check failure on line 233 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 6

syntax error: unexpected comma at end of statement

Check failure on line 233 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 5

syntax error: unexpected comma at end of statement
=======

Check failure on line 234 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 6

syntax error: unexpected ==, expecting }

Check failure on line 234 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 5

syntax error: unexpected ==, expecting }
successHandler.RecordHit(r, analytics.Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))

Check failure on line 235 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 6

syntax error: unexpected comma after top level declaration

Check failure on line 235 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 5

syntax error: unexpected comma after top level declaration
>>>>>>> 921bdc50... [TT-7127] Fix goplugin invalid memory address or nil pointer dereference (#5589)

Check failure on line 236 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 6

invalid character U+0023 '#'

Check failure on line 236 in gateway/mw_go_plugin.go

View workflow job for this annotation

GitHub Actions / Go 1.15 Redis 5

invalid character U+0023 '#'

// no need to continue passing this request down to reverse proxy
respCode = mwStatusRespond
Expand Down

0 comments on commit 2026c80

Please sign in to comment.