fix: avoid accepting directories as include files

This commit is contained in:
Rac
2026-02-10 01:15:57 +09:00
committed by Jeff Trull
parent b5af804078
commit 96e5788a45
5 changed files with 48 additions and 2 deletions
+20 -2
View File
@@ -178,6 +178,24 @@ private:
boost::filesystem::path current_dir;
boost::filesystem::path current_rel_dir;
bool may_be_includable(const boost::filesystem::path& p) const
{
namespace fs = boost::filesystem;
if (!fs::exists(p) || fs::is_directory(p)) {
return false;
}
if (fs::is_symlink(p)) {
boost::system::error_code ec;
fs::file_status target = fs::status(p, ec);
if (ec || !fs::exists(target) || fs::is_directory(target)) {
return false;
}
return true;
} else {
return true;
}
}
#if BOOST_WAVE_SUPPORT_PRAGMA_ONCE != 0
public:
bool has_pragma_once(std::string const &filename)
@@ -328,7 +346,7 @@ bool include_paths::find_include_file (std::string &s, std::string &dir,
currpath /= create_path(s); // append filename
}
if (fs::exists(currpath)) {
if (may_be_includable(currpath)) {
fs::path dirpath (create_path(s));
if (!dirpath.has_root_directory()) {
dirpath = create_path((*it).second);
@@ -362,7 +380,7 @@ include_paths::find_include_file (std::string &s, std::string &dir,
currpath /= create_path(s);
}
if (fs::exists(currpath) && 0 == current_file) {
if (0 == current_file && may_be_includable(currpath)) {
// if 0 != current_path (#include_next handling) it can't be
// the file in the current directory
fs::path dirpath(create_path(s));
+17
View File
@@ -0,0 +1,17 @@
/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2026 Rac75116. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
// Verify include lookup ignores directories named like the header.
//O -I$P(t_2_032_dir)
//O -I$P(t_2_032_inc)
//R #line 10 "t_2_032_target.hpp"
//R t_2_032_target_from_file
#include "t_2_032_target.hpp"
@@ -0,0 +1,10 @@
/*=============================================================================
Boost.Wave: A Standard compliant C++ preprocessor library
http://www.boost.org/
Copyright (c) 2026 Rac75116. Distributed under the Boost
Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
t_2_032_target_from_file
+1
View File
@@ -84,6 +84,7 @@ t_2_028.cpp
t_2_029.cpp
t_2_030.cpp
t_2_031.cpp
t_2_032.cpp
#
# t_3: Predefined macros