From 2026c80b31e9dffebf962fe1f0d69d9ed3a5a1e8 Mon Sep 17 00:00:00 2001 From: Tit Petric Date: Thu, 5 Oct 2023 14:36:36 +0200 Subject: [PATCH] [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 Co-authored-by: Chenyang Yan (cherry picked from commit 921bdc5023e79a6e830ca0cd8ac265058daf423f) --- gateway/mw_go_plugin.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gateway/mw_go_plugin.go b/gateway/mw_go_plugin.go index 6a97a4be36a..94b9a238d3a 100644 --- a/gateway/mw_go_plugin.go +++ b/gateway/mw_go_plugin.go @@ -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 } @@ -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 m.successHandler.RecordHit(r, Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r)) +======= + successHandler.RecordHit(r, analytics.Latency{Total: int64(ms)}, rw.statusCodeSent, rw.getHttpResponse(r)) +>>>>>>> 921bdc50... [TT-7127] Fix goplugin invalid memory address or nil pointer dereference (#5589) // no need to continue passing this request down to reverse proxy respCode = mwStatusRespond