Skip to content

Commit ac5be65

Browse files
Copilothecko
andcommitted
Tighten file-type checks in DSM readFile: use S_ISREG() to reject special files
Co-authored-by: hecko <855807+hecko@users.noreply.github.com>
1 parent 3bc1b5e commit ac5be65

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

apps/dsm/DSMStateDiagramCollection.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
9292
string name(ep->d_name);
9393
if (name.rfind(".dsm") != (name.size() - 4)) continue;
9494
include_dir_name = include_name + "/" + name;
95+
struct stat entry_status;
96+
if (stat(include_dir_name.c_str(), &entry_status) != 0 ||
97+
!S_ISREG(entry_status.st_mode)) continue;
9598
if (!readFile(include_dir_name, name, current_load_path, s)) {
9699
ERROR(" while processing '#include %s' (directory entry '%s') in '%s'\n",
97100
include_name.c_str(), include_dir_name.c_str(), filename.c_str());
@@ -110,7 +113,7 @@ bool DSMStateDiagramCollection::readFile(const string& filename, const string& n
110113
if (stat(include_name.c_str(), &status) != 0) {
111114
string with_ext = include_name + ".dsm";
112115
if (stat(with_ext.c_str(), &status) == 0 &&
113-
!(status.st_mode & S_IFDIR) &&
116+
S_ISREG(status.st_mode) &&
114117
with_ext != filename) {
115118
DBG("'%s' not found, using '%s'\n",
116119
include_name.c_str(), with_ext.c_str());

0 commit comments

Comments
 (0)