From: Jeff Halter Date: Tue, 23 Jul 2024 20:57:13 +0000 (-0700) Subject: Fix panic on empty news path X-Git-Url: https://git.r.bdr.sh/rbdr/mobius/commitdiff_plain/318eb6bc17ee406e26c1cfe0835409fd446bad75 Fix panic on empty news path --- diff --git a/internal/mobius/threaded_news.go b/internal/mobius/threaded_news.go index 600006a..e9d9c22 100644 --- a/internal/mobius/threaded_news.go +++ b/internal/mobius/threaded_news.go @@ -129,6 +129,10 @@ func (n *ThreadedNewsYAML) PostArticle(newsPath []string, parentArticleID uint32 binary.BigEndian.PutUint32(article.ParentArt[:], parentArticleID) + if len(newsPath) == 0 { + return fmt.Errorf("invalid news path") + } + cats := n.getCatByPath(newsPath[:len(newsPath)-1]) catName := newsPath[len(newsPath)-1] @@ -176,6 +180,10 @@ func (n *ThreadedNewsYAML) DeleteArticle(newsPath []string, articleID uint32, _ // // TODO: Handle delete recursive //} + if len(newsPath) == 0 { + return fmt.Errorf("invalid news path") + } + cats := n.getCatByPath(newsPath[:len(newsPath)-1]) catName := newsPath[len(newsPath)-1] diff --git a/internal/mobius/transaction_handlers.go b/internal/mobius/transaction_handlers.go index 3253ff2..6f734c7 100644 --- a/internal/mobius/transaction_handlers.go +++ b/internal/mobius/transaction_handlers.go @@ -1148,8 +1148,9 @@ func HandleGetNewsArtData(cc *hotline.ClientConn, t *hotline.Transaction) (res [ // None func HandleDelNewsItem(cc *hotline.ClientConn, t *hotline.Transaction) (res []hotline.Transaction) { pathStrs, err := t.GetField(hotline.FieldNewsPath).DecodeNewsPath() - if err != nil { - return res + if err != nil || len(pathStrs) == 0 { + cc.Logger.Error("invalid news path") + return nil } item := cc.Server.ThreadedNewsMgr.NewsItem(pathStrs) @@ -1217,7 +1218,8 @@ func HandlePostNewsArt(cc *hotline.ClientConn, t *hotline.Transaction) (res []ho } pathStrs, err := t.GetField(hotline.FieldNewsPath).DecodeNewsPath() - if err != nil { + if err != nil || len(pathStrs) == 0 { + cc.Logger.Error("invalid news path") return res }