From 1be5f5a51bf8a86bec3fa7c9007e5991e9fe36a5 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:35:08 +0100 Subject: [PATCH] webrtc: fix crash when reading from path 'publish' (#2688) --- internal/core/webrtc_http_server.go | 2 +- internal/core/webrtc_manager_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/core/webrtc_http_server.go b/internal/core/webrtc_http_server.go index d6fa55ac6fd4..4a471ae92d16 100644 --- a/internal/core/webrtc_http_server.go +++ b/internal/core/webrtc_http_server.go @@ -348,7 +348,7 @@ func (s *webRTCHTTPServer) onRequest(ctx *gin.Context) { case len(ctx.Request.URL.Path) >= 2: switch { - case strings.HasSuffix(ctx.Request.URL.Path, "/publish"): + case len(ctx.Request.URL.Path) > len("/publish") && strings.HasSuffix(ctx.Request.URL.Path, "/publish"): s.onPage(ctx, ctx.Request.URL.Path[1:len(ctx.Request.URL.Path)-len("/publish")], true) case ctx.Request.URL.Path[len(ctx.Request.URL.Path)-1] != '/': diff --git a/internal/core/webrtc_manager_test.go b/internal/core/webrtc_manager_test.go index 72ed4f49ee27..c56c8d2e0b91 100644 --- a/internal/core/webrtc_manager_test.go +++ b/internal/core/webrtc_manager_test.go @@ -27,7 +27,7 @@ func TestWebRTCPages(t *testing.T) { hc := &http.Client{Transport: &http.Transport{}} - for _, path := range []string{"/stream", "/stream/publish"} { + for _, path := range []string{"/stream", "/stream/publish", "/publish"} { func() { req, err := http.NewRequest(http.MethodGet, "http://localhost:8889"+path, nil) require.NoError(t, err)