mirror of
https://github.com/Icinga/icinga2.git
synced 2025-04-08 17:05:25 +02:00
GetObjectPath: ensure use of escaped name in all cases and use TruncateUsingHash()
68a0079c26686363b6202a8abd2712d2bf96d9f2 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
fc0019b271
commit
3db48de0e6
@ -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…
x
Reference in New Issue
Block a user