sipcapture / homer-app

HOMER 7.x Front-End and API Server
http://sipcapture.io
GNU Affero General Public License v3.0
204 stars 79 forks source link

homer-app: runtime error: slice bounds out of range [:50] with length 25 #367

Closed Den4t closed 4 years ago

Den4t commented 4 years ago

Hi !

This error affected in web interface as: "Bad gateway" red window in serch results form, when i try ti click on "Session ID" field.

LOG:

2020-06-27T09:10:55.083332129Z echo: http: panic serving 172.18.0.4:51744: runtime error: slice bounds out of range [:50] with length 25 2020-06-27T09:10:55.083352047Z goroutine 165 [running]: 2020-06-27T09:10:55.083355631Z net/http.(conn).serve.func1(0xc00020c280) 2020-06-27T09:10:55.083359386Z /usr/local/go/src/net/http/server.go:1772 +0x139 2020-06-27T09:10:55.083362411Z panic(0xd38100, 0xc00049ef60) 2020-06-27T09:10:55.083365441Z /usr/local/go/src/runtime/panic.go:975 +0x3e3 2020-06-27T09:10:55.083368393Z github.com/sipcapture/homer-app/data/service.(SearchService).getTransactionSummary(0xc0000737c0, 0xc00059a000, 0xc00001b288, 0xc00059a000, 0x0) 2020-06-27T09:10:55.083371618Z /homer-app/data/service/search.go:1013 +0x3888 2020-06-27T09:10:55.083374214Z github.com/sipcapture/homer-app/data/service.(SearchService).GetTransaction(0xc0000737c0, 0xc0003a5310, 0x10, 0xc0000f2600, 0xff, 0x100, 0xc00022a600, 0x588, 0x588, 0x4b7c00, ...) 2020-06-27T09:10:55.083377212Z /homer-app/data/service/search.go:807 +0x2331 2020-06-27T09:10:55.083379869Z github.com/sipcapture/homer-app/controller/v1.(SearchController).GetTransaction(0xc00000cb80, 0xf29ea0, 0xc000527260, 0xc000527260, 0xd90a80) 2020-06-27T09:10:55.083382732Z /homer-app/controller/v1/search.go:196 +0x431 2020-06-27T09:10:55.083385334Z github.com/sipcapture/homer-app/auth.MiddlewareRes.func1(0xf29ce0, 0xc000510070, 0x4, 0xcade80) 2020-06-27T09:10:55.083387956Z /homer-app/auth/middleware.go:24 +0x1eb 2020-06-27T09:10:55.083390449Z github.com/labstack/echo/v4/middleware.JWTWithConfig.func2.1(0xf29ce0, 0xc000510070, 0xc000638005, 0xda1ba3) 2020-06-27T09:10:55.083393011Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/middleware/jwt.go:181 +0x2ff 2020-06-27T09:10:55.083395820Z github.com/labstack/echo/v4.(Echo).Add.func1(0xf29ce0, 0xc000510070, 0xd09e01, 0xc00011a101) 2020-06-27T09:10:55.083420548Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/echo.go:490 +0x8a 2020-06-27T09:10:55.083425289Z github.com/labstack/echo/v4/middleware.GzipWithConfig.func1.1(0xf29ce0, 0xc000510070, 0x0, 0x0) 2020-06-27T09:10:55.083428003Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/middleware/compress.go:64 +0x58f 2020-06-27T09:10:55.083430560Z github.com/labstack/echo/v4/middleware.StaticWithConfig.func1.1(0xf29ce0, 0xc000510070, 0xdc04c8, 0x1b) 2020-06-27T09:10:55.083433065Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/middleware/static.go:169 +0x2b9 2020-06-27T09:10:55.083435660Z github.com/labstack/echo/v4/middleware.CORSWithConfig.func1.1(0xf29ce0, 0xc000510070, 0x4, 0xc000638005) 2020-06-27T09:10:55.083438163Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/middleware/cors.go:117 +0x407 2020-06-27T09:10:55.083440774Z github.com/labstack/echo/v4.(Echo).ServeHTTP.func1(0xf29ce0, 0xc000510070, 0xc000093b01, 0x849d5d) 2020-06-27T09:10:55.083443997Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/echo.go:585 +0x108 2020-06-27T09:10:55.083446532Z github.com/labstack/echo/v4/middleware.RewriteWithConfig.func1.1(0xf29ce0, 0xc000510070, 0xc000510070, 0x2739b19d) 2020-06-27T09:10:55.083449120Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/middleware/rewrite.go:68 +0x1ff 2020-06-27T09:10:55.083451696Z github.com/labstack/echo/v4.(Echo).ServeHTTP(0xc000120000, 0xf0e6e0, 0xc0001620e0, 0xc000518200) 2020-06-27T09:10:55.083454201Z /go/pkg/mod/github.com/labstack/echo/v4@v4.0.0/echo.go:593 +0x222 2020-06-27T09:10:55.083456734Z net/http.serverHandler.ServeHTTP(0xc000110000, 0xf0e6e0, 0xc0001620e0, 0xc000518200) 2020-06-27T09:10:55.083459421Z /usr/local/go/src/net/http/server.go:2807 +0xa3 2020-06-27T09:10:55.083461842Z net/http.(conn).serve(0xc00020c280, 0xf11720, 0xc0000bc200) 2020-06-27T09:10:55.083464280Z /usr/local/go/src/net/http/server.go:1895 +0x86c 2020-06-27T09:10:55.083468048Z created by net/http.(*Server).Serve 2020-06-27T09:10:55.083470507Z /usr/local/go/src/net/http/server.go:2933 +0x35c

Solution:

--- search.go.orig      2020-06-27 13:15:42.665253995 +0300
+++ search.go   2020-06-27 12:20:02.701852527 +0300
@@ -1010,7 +1010,9 @@
                }
                if dataElement.Exists("raw") {
                        callElement.RuriUser = dataElement.S("raw").Data().(string)
-                       callElement.RuriUser = callElement.RuriUser[:50]
+                       if len(callElement.RuriUser) > 50 {
+                               callElement.RuriUser = callElement.RuriUser[:50]
+                       }
                }

                callElement.SrcID = callElement.SrcHost + ":" + strconv.FormatFloat(callElement.SrcPort, 'f', 0, 64)
adubovikov commented 4 years ago

Thank you! Can you please make a PR ?

adubovikov commented 4 years ago

ok. I did it by myself. Please next time make a PR :-)

thank you! https://github.com/sipcapture/homer-app/commit/abefb2814d65bda22d191532b98e787e79ae0a4a