mirror of https://github.com/Icinga/icinga2.git
GetObjectPath: ensure use of escaped name in all cases and use TruncateUsingHash()
68a0079c26
introduced two problems that are fixed
with this commit:
1. The new truncated/hashed name did not use EscapeName()
2. There was a possible collision of names when creating objects with a full
name of format "[80 characters]...[40 hex digits]" (i.e. the same as the
truncated/hashed variant but short enough that it isn't hashed)
This commit is contained in:
parent
97d6876803
commit
e079762c8e
|
@ -35,15 +35,17 @@ String ConfigObjectUtility::GetObjectConfigPath(const Type::Ptr& type, const Str
|
|||
boost::algorithm::to_lower(typeDir);
|
||||
|
||||
/* This may throw an exception the caller above must handle. */
|
||||
String prefix = GetConfigDir();
|
||||
String prefix = GetConfigDir() + "/conf.d/" + type->GetPluralName().ToLower() + "/";
|
||||
|
||||
auto old (prefix + "/conf.d/" + typeDir + "/" + EscapeName(fullName) + ".conf");
|
||||
String escapedName = EscapeName(fullName);
|
||||
|
||||
if (fullName.GetLength() <= 80u + 3u /* "..." */ + 40u /* hex SHA1 */ || Utility::PathExists(old)) {
|
||||
String old = prefix + escapedName + ".conf";
|
||||
if (Utility::PathExists(old)) {
|
||||
return std::move(old);
|
||||
}
|
||||
|
||||
return prefix + "/conf.d/" + typeDir + "/" + fullName.SubStr(0, 80) + "..." + SHA1(fullName) + ".conf";
|
||||
/* Maximum length 80 bytes object name + 3 bytes "..." + 40 bytes SHA1 (hex-encoded) */
|
||||
return prefix + Utility::TruncateUsingHash<80+3+40>(escapedName) + ".conf";
|
||||
}
|
||||
|
||||
void ConfigObjectUtility::RepairPackage(const String& package)
|
||||
|
|
Loading…
Reference in New Issue