Skip to content

Commit

Permalink
Fix panic on empty news path
Browse files Browse the repository at this point in the history
  • Loading branch information
jhalter committed Jul 23, 2024
1 parent 3e4a52e commit 318eb6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 8 additions & 0 deletions internal/mobius/threaded_news.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 5 additions & 3 deletions internal/mobius/transaction_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 318eb6b

Please sign in to comment.