diff --git a/core/commands/cidstore.go b/core/commands/cidstore.go index 21e56cbc0..08421d8e0 100644 --- a/core/commands/cidstore.go +++ b/core/commands/cidstore.go @@ -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" ) @@ -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, @@ -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 +}