Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed FilesystemPath::isFile return value. #491

Merged
merged 2 commits into from
Feb 10, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# dev

* Fix: FilesystemPath::isFile ([#490] (https://github.com/avast-tl/retdec/issues/490)).
* New Feature: Added presentation of imported types and TypeRef hashes for .NET binaries ([#363](https://github.com/avast-tl/retdec/issues/363), [#364](https://github.com/avast-tl/retdec/issues/364), [#428](https://github.com/avast-tl/retdec/issues/428)).
* New Feature: Added computation and presentation of icon hashes for exact and also similarity matching in PE files ([#339](https://github.com/avast-tl/retdec/issues/339)).
* Enhancement: Added support for build and run on FreeBSD and potentially on other BSD OSes ([#476](https://github.com/avast-tl/retdec/pull/476)).
Expand Down
20 changes: 12 additions & 8 deletions src/utils/filesystem_path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class FilesystemPathImplWindows : public FilesystemPathImpl

subpaths.clear();
HANDLE hFnd = FindFirstFile(examineDir.c_str(), &ffd);
if (hFnd == reinterpret_cast<HANDLE>(-1))
if (hFnd == INVALID_HANDLE_VALUE)
return false;

do
Expand All @@ -141,16 +141,16 @@ class FilesystemPathImplWindows : public FilesystemPathImpl

virtual bool isFile() override
{
return !isDirectory();
DWORD attributes = GetFileAttributes(_path.c_str());
return (attributes != INVALID_FILE_ATTRIBUTES) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY) == 0;
}

virtual bool isDirectory() override
{
WIN32_FIND_DATA ffd;
if (FindFirstFile(_path.c_str(), &ffd) == reinterpret_cast<HANDLE>(-1))
return false;

return ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
DWORD attributes = GetFileAttributes(_path.c_str());
return (attributes != INVALID_FILE_ATTRIBUTES) &&
(attributes & FILE_ATTRIBUTE_DIRECTORY);
}

virtual bool isAbsolute() override
Expand Down Expand Up @@ -231,7 +231,11 @@ class FilesystemPathImplUnix : public FilesystemPathImpl

virtual bool isFile() override
{
return !isDirectory();
struct stat st;
if (stat(_path.c_str(), &st) != 0)
return false;

return S_ISREG(st.st_mode);
}

virtual bool isDirectory() override
Expand Down