@@ -116,15 +116,19 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
116
116
for (auto const & prefix: prefixes)
117
117
{
118
118
boost::filesystem::path canonicalPath = normalizeCLIPathForVFS (prefix / strippedSourceUnitName, SymlinkResolution::Enabled);
119
-
120
119
if (boost::filesystem::exists (canonicalPath))
121
120
candidates.push_back (std::move (canonicalPath));
122
121
}
123
122
124
123
auto pathToQuotedString = [](boost::filesystem::path const & _path){ return " \" " + _path.string () + " \" " ; };
125
124
126
125
if (candidates.empty ())
127
- return ReadCallback::Result{false , " File not found." };
126
+ return ReadCallback::Result{
127
+ false ,
128
+ " File not found. Searched the following locations: " +
129
+ joinHumanReadable (prefixes | ranges::views::transform (pathToQuotedString), " , " ) +
130
+ " ."
131
+ };
128
132
129
133
if (candidates.size () >= 2 )
130
134
return ReadCallback::Result{
@@ -135,19 +139,26 @@ ReadCallback::Result FileReader::readFile(string const& _kind, string const& _so
135
139
" ."
136
140
};
137
141
138
- FileSystemPathSet extraAllowedPaths = {m_basePath.empty () ? " ." : m_basePath};
139
- extraAllowedPaths += m_includePaths;
142
+ FileSystemPathSet allowedPaths =
143
+ m_allowedDirectories +
144
+ decltype (allowedPaths){m_basePath.empty () ? " ." : m_basePath} +
145
+ m_includePaths;
140
146
141
147
bool isAllowed = false ;
142
- for (boost::filesystem::path const & allowedDir: m_allowedDirectories + extraAllowedPaths )
148
+ for (boost::filesystem::path const & allowedDir: allowedPaths )
143
149
if (isPathPrefix (normalizeCLIPathForVFS (allowedDir, SymlinkResolution::Enabled), candidates[0 ]))
144
150
{
145
151
isAllowed = true ;
146
152
break ;
147
153
}
148
154
149
155
if (!isAllowed)
150
- return ReadCallback::Result{false , " File outside of allowed directories." };
156
+ return ReadCallback::Result{
157
+ false ,
158
+ " File outside of allowed directories. The following are allowed: " +
159
+ joinHumanReadable (allowedPaths | ranges::views::transform (pathToQuotedString), " , " ) +
160
+ " ."
161
+ };
151
162
152
163
if (!boost::filesystem::is_regular_file (candidates[0 ]))
153
164
return ReadCallback::Result{false , " Not a valid file." };
0 commit comments