File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 16
16
* limitations under the License.
17
17
*/
18
18
19
+ #include < sys/stat.h>
19
20
#include < fstream>
20
21
#include < list>
21
22
#include < unordered_map>
@@ -216,6 +217,16 @@ std::string GetParentDirectory(const std::string& path) {
216
217
return path.substr (0 , pos + 1 );
217
218
}
218
219
220
+ bool isRegularFile (const std::string& path) {
221
+ struct stat info;
222
+
223
+ if (stat (path.c_str (), &info) != 0 )
224
+ return false ;
225
+
226
+ // Check if it's a regular file
227
+ return (info.st_mode & S_IFMT) == S_IFREG;
228
+ }
229
+
219
230
} // namespace
220
231
221
232
Config::Config () : internal(new ConfigInternal()) {}
@@ -241,6 +252,8 @@ ConverterPtr Config::NewFromFile(const std::string& fileName,
241
252
impl->paths .push_back (PACKAGE_DATA_DIRECTORY);
242
253
}
243
254
std::string prefixedFileName = impl->FindConfigFile (fileName);
255
+ if (!isRegularFile (prefixedFileName))
256
+ throw FileNotFound (prefixedFileName);
244
257
std::ifstream ifs (UTF8Util::GetPlatformString (prefixedFileName));
245
258
std::string content (std::istreambuf_iterator<char >(ifs),
246
259
(std::istreambuf_iterator<char >()));
You can’t perform that action at this time.
0 commit comments