You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coming here from an audit, client.parseQueryStorePath and client.isQueryStoreWithProof are untested, yet is in the path of querying the ABCI and verifying proofs.
return"", errors.New("expected path to start with /")
}
paths:=strings.SplitN(path[1:], "/", 3)
switch {
caselen(paths) !=3:
return"", errors.New("expected format like /store/<storeName>/key")
casepaths[0] !="store":
return"", errors.New("expected format like /store/<storeName>/key")
casepaths[2] !="key":
return"", errors.New("expected format like /store/<storeName>/key")
}
returnpaths[1], nil
}
Problems
Code duplication
Notice that they have pretty much the same logic except one returns a boolean, the other returns (string, error). We can fold isQueryStoreWithProof to simply be
Rigid path requirement for a mistake that most users make aka a slash affixed at the end of a path
Passing in a path such as /store/foo/key/ will fail, but /store/foo/key will pass. Think about how common it is to use tab completion on the command-line and what your paths look like after tab completion, usually in the form /store/foo/key/.
We can fix this code by a special ingredient strings.Trim(path, "/") aka
// Trim off the first and last slashes.path=strings.Trim(path, "/")
paths:=strings.SplitN(path, "/", 3)
and finally the code will look like this
// parseQueryStorePath expects a format like /store/<storeName>/key.funcparseQueryStorePath(pathstring) (storeNamestring, errerror) {
if!strings.HasPrefix(path, "/") {
return"", errors.New("expected path to start with /")
}
// Trim off the first and last slashes.path=strings.Trim(path, "/")
paths:=strings.SplitN(path, "/", 3)
switch {
caselen(paths) !=3:
return"", errors.New("expected format like /store/<storeName>/key")
casepaths[0] !="store":
return"", errors.New("expected format like /store/<storeName>/key")
casepaths[2] !="key":
return"", errors.New("expected format like /store/<storeName>/key")
}
returnpaths[1], nil
}
Coming here from an audit, client.parseQueryStorePath and client.isQueryStoreWithProof are untested, yet is in the path of querying the ABCI and verifying proofs.
The source code to both looks like this
isQueryStoreWithProof
cosmos-sdk/client/query.go
Lines 198 to 215 in 13b5a8d
parseQueryStorePath
cosmos-sdk/client/query.go
Lines 218 to 235 in 13b5a8d
Problems
Code duplication
Notice that they have pretty much the same logic except one returns a boolean, the other returns (string, error). We can fold isQueryStoreWithProof to simply be
Rigid path requirement for a mistake that most users make aka a slash affixed at the end of a path
Passing in a path such as
/store/foo/key/
will fail, but/store/foo/key
will pass. Think about how common it is to use tab completion on the command-line and what your paths look like after tab completion, usually in the form/store/foo/key/
.We can fix this code by a special ingredient strings.Trim(path, "/") aka
and finally the code will look like this
and here is a full test that'll cover bases
For Admin Use
The text was updated successfully, but these errors were encountered: