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

Correct usage of stat.st_mode result for testing S_IFREG and S_IFDIR #421

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

nbriggs
Copy link
Collaborator

@nbriggs nbriggs commented Mar 29, 2022

stat.st_mode cannot be tested for whether a node is S_IFDIR with
if (stat.st_mode & S_IFDIR) ...
since S_IFDIR bit (0040000) is a subset of S_IFSOCK (0140000) bits.
A correct check is
if ((stat.st_mode & S_IFMT) == S_IFDIR) ...
or alternatively, since the convenience macros are defined on all modern systems
if (S_ISDIR(stat.st_mode)) ...

stat.st_mode cannot be tested for whether a node is S_IFDIR with
    if (stat.st_mode & S_IFDIR) ...
since S_IFDIR bit (0040000) is a subset of S_IFSOCK (0140000) bits.
A correct check is
    if ((stat.st_mode & S_IFMT) == S_IFDIR) ...
or alternatively, since the convenience macros are defined on all modern systems
    if (S_ISDIR(stat.st_mode)) ...
@nbriggs nbriggs requested a review from rmkaplan March 29, 2022 21:33
@nbriggs nbriggs merged commit 2bf7047 into master Mar 30, 2022
@nbriggs nbriggs deleted the bad_file_type_discrimination branch May 19, 2022 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant