Skip to content

Commit

Permalink
Merging to release-4-lts: [TT-7127] Fix goplugin invalid memory addre…
Browse files Browse the repository at this point in the history
…ss or nil pointer dereference (#5589) (#5594)

[TT-7127] Fix goplugin invalid memory address or nil pointer dereference
(#5589)

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

Closes #4198 #4197

Signed-off-by: Chenyang Yan <memory.yancy@gmail.com>
Co-authored-by: Chenyang Yan <memory.yancy@gmail.com>

[TT-7127]:
https://tyktech.atlassian.net/browse/TT-7127?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Tit Petric <tit.petric@monotek.net>
Co-authored-by: Tit Petric <tit@tyk.io>
  • Loading branch information
3 people authored and lghiur committed Jan 22, 2024
1 parent d3bfe9f commit 4fa6a1e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions 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,7 @@ 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
m.successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))
successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r))

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

0 comments on commit 4fa6a1e

Please sign in to comment.