diff options
| author | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-23 13:57:13 -0700 |
|---|---|---|
| committer | Jeff Halter <868228+jhalter@users.noreply.github.com> | 2024-07-23 13:58:12 -0700 |
| commit | 318eb6bc17ee406e26c1cfe0835409fd446bad75 (patch) | |
| tree | 6a5709c676c505d7a2fb091c167976f02392fa55 /internal | |
| parent | 3e4a52ed34b130743164d6d77f31a1fc67f161c8 (diff) | |
Fix panic on empty news path
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/mobius/threaded_news.go | 8 | ||||
| -rw-r--r-- | internal/mobius/transaction_handlers.go | 8 |
2 files changed, 13 insertions, 3 deletions
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 } |