1
0
Fork 0

Fix potential segfault (#9308)

* Check whether name is empty in getCollectionId{Local,Cluster} before access
This commit is contained in:
Markus Pfeiffer 2019-11-21 11:33:05 +00:00 committed by Michael Hackstein
parent ba2b11f766
commit e11e81e0b7
1 changed files with 11 additions and 5 deletions

View File

@ -70,7 +70,11 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollection(std::st
//////////////////////////////////////////////////////////////////////////////
TRI_voc_cid_t CollectionNameResolver::getCollectionIdLocal(std::string const& name) const {
if (name[0] >= '0' && name[0] <= '9') {
if (name.empty()) {
return 0;
}
if (isdigit(name[0])) {
// name is a numeric id
return NumberUtils::atoi_zero<TRI_voc_cid_t>(name.data(), name.data() + name.size());
}
@ -82,7 +86,6 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdLocal(std::string const& na
}
auto view = _vocbase.lookupView(name);
if (view) {
return view->id();
}
@ -101,7 +104,10 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(std::string const&
if (!ServerState::isRunningInCluster(_serverRole)) {
return getCollectionIdLocal(name);
}
if (name[0] >= '0' && name[0] <= '9') {
if (name.empty()) {
return 0;
}
if (isdigit(name[0])) {
// name is a numeric id
TRI_voc_cid_t cid =
NumberUtils::atoi_zero<TRI_voc_cid_t>(name.data(), name.data() + name.size());