Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/common/config/config_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ bool ConfigFile::wildCards(const char* currentFileName, const PathName& pathPref
// Any change in directory can cause config change
PathName prefix(pathPrefix);
if(!pathPrefix.hasData())
prefix = ".";
prefix = PathUtils::curr_dir_link;

bool found = false;
PathName next(components.pop());
Expand All @@ -761,7 +761,7 @@ bool ConfigFile::wildCards(const char* currentFileName, const PathName& pathPref
{
PathName name;
const PathName fileName = list.getFileName();
if (fileName == ".")
if (fileName == PathUtils::curr_dir_link)
continue;
if (fileName[0] == '.' && next[0] != '.')
continue;
Expand Down
85 changes: 38 additions & 47 deletions src/common/config/dir_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,44 @@ void ParsedPath::parse(const PathName& path)
{
clear();

if (path.length() == 1) {
add(path);
return;
}

PathName oldpath = path;
int toSkip = 0;
do {
PathName newpath, elem;
PathUtils::splitLastComponent(newpath, elem, oldpath);
oldpath = newpath;
if (elem.isEmpty() && !oldpath.isEmpty()) // Skip double dir separator
{
continue;
}
if (elem == PathUtils::curr_dir_link) // Skip current dir reference
{
continue;
}
if (elem == PathUtils::up_dir_link) // skip next up dir
Copy link
Copy Markdown
Member

@asfernandes asfernandes May 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does FB still run (compiles for) in Win 9X based kernels? I do remember in this OS "..." (or more dots) was valid part of paths, meaning "...." and so. Is this compatible? Or is the old code (2.X) compatible with this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR, Firebird doesn't support Win9X anymore.
Neither Windows 8 nor Linux support three dots in path.

{
toSkip++;
continue;
}
if (toSkip > 0)
{
toSkip--;
continue;
}
insert(0, elem);
} while (oldpath.length() > 0);
if (toSkip != 0)
{
// Malformed path, attempt to hack?..
// Let it be, consequent comparison will rule it out
}
}

PathName ParsedPath::subPath(FB_SIZE_T n) const
{
PathName rc = (*this)[0];
if (PathUtils::isRelative(rc + PathUtils::dir_sep))
rc = PathUtils::dir_sep + rc;
if (rc.isEmpty())
rc = PathUtils::dir_sep;
for (FB_SIZE_T i = 1; i < n; i++)
{
PathName newpath;
Expand Down Expand Up @@ -155,42 +174,23 @@ void DirectoryList::initialize(bool simple_mode)
}
}

FB_SIZE_T last = 0;
PathName root = Config::getRootDirectory();
FB_SIZE_T i;
for (i = 0; i < val.length(); i++)
while (!val.isEmpty())
{
if (val[i] == ';')
string::size_type sep = val.find(';');
if (sep == string::npos)
sep = val.length();
PathName dir(val.c_str(), sep);
dir.alltrim(" \t\r");
val.erase(0, sep + 1);
if (PathUtils::isRelative(dir))
{
PathName dir = "";
if (i > last)
{
dir = val.substr(last, i - last);
dir.trim();
}
if (PathUtils::isRelative(dir))
{
PathName newdir;
PathUtils::concatPath(newdir, root, dir);
dir = newdir;
}
add(ParsedPath(dir));
last = i + 1;
PathName fullPath;
PathUtils::concatPath(fullPath, root, dir);
dir = fullPath;
}
add(ParsedPath(dir));
}
PathName dir = "";
if (i > last)
{
dir = val.substr(last, i - last);
dir.trim();
}
if (PathUtils::isRelative(dir))
{
PathName newdir;
PathUtils::concatPath(newdir, root, dir);
dir = newdir;
}
add(ParsedPath(dir));
}

bool DirectoryList::isPathInList(const PathName& path) const
Expand All @@ -211,15 +211,6 @@ bool DirectoryList::isPathInList(const PathName& path) const
return true;
}

// Disable any up-dir(..) references - in case our path_utils
// and OS handle paths in slightly different ways,
// this is "wonderful" potential hole for hacks
// Example of IIS attack attempt:
// "GET /scripts/..%252f../winnt/system32/cmd.exe?/c+dir HTTP/1.0"
// (live from apache access.log :)
if (path.find(PathUtils::up_dir_link) != PathName::npos)
return false;

PathName varpath(path);
if (PathUtils::isRelative(path)) {
PathUtils::concatPath(varpath, PathName(Config::getRootDirectory()), path);
Expand Down
3 changes: 3 additions & 0 deletions src/common/os/path_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class PathUtils
/// The directory separator for the platform.
static const char dir_sep;

/// String used to point to current directory
static const char* curr_dir_link;

/// String used to point to parent directory
static const char* up_dir_link;

Expand Down
1 change: 1 addition & 0 deletions src/common/os/posix/path_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
/// The POSIX implementation of the path_utils abstraction.

const char PathUtils::dir_sep = '/';
const char* PathUtils::curr_dir_link = ".";
const char* PathUtils::up_dir_link = "..";
const char PathUtils::dir_list_sep = ':';

Expand Down
1 change: 1 addition & 0 deletions src/common/os/win32/path_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/// The Win32 implementation of the path_utils abstraction.

const char PathUtils::dir_sep = '\\';
const char* PathUtils::curr_dir_link = ".";
const char* PathUtils::up_dir_link = "..";
const char PathUtils::dir_list_sep = ';';

Expand Down