Skip to content

Commit

Permalink
fix: add cid check
Browse files Browse the repository at this point in the history
  • Loading branch information
cody.meng committed Dec 18, 2024
1 parent 56947fc commit 53e5f5c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions core/commands/cidstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

cmds "github.com/bittorrent/go-btfs-cmds"
"github.com/bittorrent/go-btfs/core/commands/cmdenv"
"github.com/ipfs/go-cid"
"github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/query"
)
Expand Down Expand Up @@ -63,6 +64,12 @@ var addCidCmd = &cmds.Command{
return cmds.EmitOnce(res, err.Error())
}

// check if all cid is valid if not return
err = validateCIDs(cids)
if err != nil {
return cmds.EmitOnce(res, err.Error())
}

// delete all exits
results, err := nd.Repo.Datastore().Query(req.Context, query.Query{
Prefix: FilterKeyPrefix,
Expand Down Expand Up @@ -205,3 +212,13 @@ var listCidCmd = &cmds.Command{
func NewGatewayFilterKey(key string) string {
return fmt.Sprintf("%s/%s", FilterKeyPrefix, key)
}

func validateCIDs(cids []string) error {
for _, c := range cids {
_, err := cid.Decode(c)
if err != nil {
return fmt.Errorf("Invalid CID: %s", c)
}
}
return nil
}

0 comments on commit 53e5f5c

Please sign in to comment.