mirror of https://gitee.com/bigwinds/arangodb
Fix potential segfault (#9308)
* Check whether name is empty in getCollectionId{Local,Cluster} before access
This commit is contained in:
parent
ba2b11f766
commit
e11e81e0b7
|
@ -70,7 +70,11 @@ std::shared_ptr<LogicalCollection> CollectionNameResolver::getCollection(std::st
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
TRI_voc_cid_t CollectionNameResolver::getCollectionIdLocal(std::string const& name) const {
|
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
|
// name is a numeric id
|
||||||
return NumberUtils::atoi_zero<TRI_voc_cid_t>(name.data(), name.data() + name.size());
|
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);
|
auto view = _vocbase.lookupView(name);
|
||||||
|
|
||||||
if (view) {
|
if (view) {
|
||||||
return view->id();
|
return view->id();
|
||||||
}
|
}
|
||||||
|
@ -101,7 +104,10 @@ TRI_voc_cid_t CollectionNameResolver::getCollectionIdCluster(std::string const&
|
||||||
if (!ServerState::isRunningInCluster(_serverRole)) {
|
if (!ServerState::isRunningInCluster(_serverRole)) {
|
||||||
return getCollectionIdLocal(name);
|
return getCollectionIdLocal(name);
|
||||||
}
|
}
|
||||||
if (name[0] >= '0' && name[0] <= '9') {
|
if (name.empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (isdigit(name[0])) {
|
||||||
// name is a numeric id
|
// name is a numeric id
|
||||||
TRI_voc_cid_t cid =
|
TRI_voc_cid_t cid =
|
||||||
NumberUtils::atoi_zero<TRI_voc_cid_t>(name.data(), name.data() + name.size());
|
NumberUtils::atoi_zero<TRI_voc_cid_t>(name.data(), name.data() + name.size());
|
||||||
|
|
Loading…
Reference in New Issue