mirror of
https://github.com/boostorg/wave.git
synced 2026-07-21 13:43:40 +00:00
fix: avoid accepting directories as include files
This commit is contained in:
@@ -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));
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user