Made length checks more robusts + bumped sizes, fixes #496
This commit is contained in:
@@ -96,9 +96,12 @@ namespace lms::db
|
||||
} // namespace
|
||||
|
||||
Cluster::Cluster(ObjectPtr<ClusterType> type, std::string_view name)
|
||||
: _name{ std::string{ name, 0, _maxNameLength } }
|
||||
: _name{ name }
|
||||
, _clusterType{ getDboPtr(type) }
|
||||
{
|
||||
// As we use the name to uniquely identify clusters and cluster types, we must throw (and not truncate)
|
||||
if (name.size() > maxNameLength)
|
||||
throw Exception{ "Cluster name is too long: " + std::string{ name } + "'" };
|
||||
}
|
||||
|
||||
Cluster::pointer Cluster::create(Session& session, ObjectPtr<ClusterType> type, std::string_view name)
|
||||
@@ -183,6 +186,9 @@ namespace lms::db
|
||||
ClusterType::ClusterType(std::string_view name)
|
||||
: _name{ name }
|
||||
{
|
||||
// As we use the name to uniquely identify clusters and cluster types, we must throw
|
||||
if (name.size() > maxNameLength)
|
||||
throw Exception{ "ClusterType name is too long: " + std::string{ name } + "'" };
|
||||
}
|
||||
|
||||
ClusterType::pointer ClusterType::create(Session& session, std::string_view name)
|
||||
@@ -230,6 +236,9 @@ namespace lms::db
|
||||
{
|
||||
session.checkReadTransaction();
|
||||
|
||||
if (name.size() > maxNameLength)
|
||||
throw Exception{ "Requested ClusterType name is too long: " + std::string{ name } + "'" };
|
||||
|
||||
return utils::fetchQuerySingleResult(session.getDboSession()->find<ClusterType>().where("name = ?").bind(name));
|
||||
}
|
||||
|
||||
@@ -254,6 +263,9 @@ namespace lms::db
|
||||
assert(self());
|
||||
assert(session());
|
||||
|
||||
if (name.size() > Cluster::maxNameLength)
|
||||
throw Exception{ "Requested Cluster name is too long: " + std::string{ name } + "'" };
|
||||
|
||||
return utils::fetchQuerySingleResult(session()->find<Cluster>().where("name = ?").bind(name).where("cluster_type_id = ?").bind(getId()));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user