aboutsummaryrefslogtreecommitdiff
path: root/src/zenserver/storage/localrefpolicy.cpp
blob: 47ef13b287229d0f4fdea4cc58d40f4146dbe168 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright Epic Games, Inc. All Rights Reserved.

#include "localrefpolicy.h"

#include <zencore/except_fmt.h>
#include <zencore/fmtutils.h>

#include <filesystem>

namespace zen {

DataRootLocalRefPolicy::DataRootLocalRefPolicy(const std::filesystem::path& DataRoot)
: m_CanonicalRoot(std::filesystem::weakly_canonical(DataRoot).string())
{
}

void
DataRootLocalRefPolicy::ValidatePath(const std::filesystem::path& Path) const
{
	std::filesystem::path CanonicalFile = std::filesystem::weakly_canonical(Path);
	std::string			  FileStr		= CanonicalFile.string();

	if (FileStr.size() < m_CanonicalRoot.size() || FileStr.compare(0, m_CanonicalRoot.size(), m_CanonicalRoot) != 0)
	{
		throw zen::invalid_argument("local file reference '{}' is outside allowed data root", CanonicalFile);
	}
}

}  // namespace zen