From ac798ac2d2cdf936b653577d9acd4b7d1e22ecaf Mon Sep 17 00:00:00 2001 From: Nadia Santalla Date: Sun, 15 Sep 2024 16:57:23 +0200 Subject: [PATCH] fix(playlist): fix non-admin users not being able to create playlists (#524) * fix(playlist): fail early if playlist path is a directory * fix(playlist): check error before assuming playlist loaded --- playlist/playlist.go | 4 ++++ server/ctrlsubsonic/handlers_playlist.go | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/playlist/playlist.go b/playlist/playlist.go index e51dbc16..c3bec6a5 100644 --- a/playlist/playlist.go +++ b/playlist/playlist.go @@ -94,6 +94,10 @@ func (s *Store) Read(relPath string) (*Playlist, error) { return nil, fmt.Errorf("stat m3u: %w", err) } + if stat.IsDir() { + return nil, errors.New("path is a directory") + } + var playlist Playlist playlist.UpdatedAt = stat.ModTime() diff --git a/server/ctrlsubsonic/handlers_playlist.go b/server/ctrlsubsonic/handlers_playlist.go index ca0c6e5c..8426f8af 100644 --- a/server/ctrlsubsonic/handlers_playlist.go +++ b/server/ctrlsubsonic/handlers_playlist.go @@ -75,8 +75,10 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response playlistPath := playlistIDDecode(playlistID) var playlist playlistp.Playlist - if pl, _ := c.playlistStore.Read(playlistPath); pl != nil { - playlist = *pl + if playlistPath != "" { + if pl, err := c.playlistStore.Read(playlistPath); err != nil && pl != nil { + playlist = *pl + } } if playlist.UserID != 0 && playlist.UserID != user.ID {