]> git.r.bdr.sh - rbdr/mobius/commitdiff
Fix panic on empty news path
authorJeff Halter <redacted>
Tue, 23 Jul 2024 20:57:13 +0000 (13:57 -0700)
committerJeff Halter <redacted>
Tue, 23 Jul 2024 20:58:12 +0000 (13:58 -0700)
internal/mobius/threaded_news.go
internal/mobius/transaction_handlers.go

index 600006abb2a552d99e6d9ff62736ea9308d0e6d7..e9d9c229a6f0d90a2b7dcea77f3ae249530fa799 100644 (file)
@@ -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]
index 3253ff247a58d5285df4625e94c7aa4da6197b5f..6f734c783a0e02c5c645328bbdf03fa1bdadd597 100644 (file)
@@ -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
        }