Skip to content

Commit

Permalink
Add length check for dirsDepth
Browse files Browse the repository at this point in the history
This change adds index checks before `dirDepths[collectionIndexDirDepth]` and `dirDepths[collectionNameDepth]` to avoid indexing beyond the end of the array. We *could* just check for the `collectionIndexDirDepth` and avoid the other two, but that would be more brittle in case the constants defined a few lines earlier were reordered. We could also just calculate `len(dirsDepth)` once as a small perf improvement.

This is related to the [suggestion](hyperledger#1080 (review)) from @manish-sethi in hyperledger#1080.
  • Loading branch information
scovetta authored Jul 10, 2020
1 parent b70cb1e commit cf6ab18
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/ledger/kvledger/txmgmt/privacyenabledstate/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ func getIndexInfo(indexPath string) *indexInfo {
indexInfo.hasIndexForChaincode = true
case len(dirsDepth) > collectionDirDepth &&
dirsDepth[collectionDirDepth] == "collections" &&
dirsDepth[collectionIndexDirDepth] == "indexes":
len(dirsDepth) > collectionIndexDirDepth &&
dirsDepth[collectionIndexDirDepth] == "indexes" &&
len(dirsDepth) > collectionNameDepth:
indexInfo.hasIndexForCollection = true
indexInfo.collectionName = dirsDepth[collectionNameDepth]
}
Expand Down

0 comments on commit cf6ab18

Please sign in to comment.