Merge pull request #7073 from alexreg/issue-7068

audit: ignore group write bit
This commit is contained in:
Mike McQuaid 2020-03-06 14:08:45 +00:00 committed by GitHub
commit 78140cef4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 9 deletions

View File

@ -242,15 +242,26 @@ module Homebrew
end end
def audit_file def audit_file
# Under normal circumstances (umask 0022), we expect a file mode of 644. If
# the user's umask is more restrictive, respect that by masking out the
# corresponding bits. (The also included 0100000 flag means regular file.)
wanted_mode = 0100644 & ~File.umask
actual_mode = formula.path.stat.mode actual_mode = formula.path.stat.mode
unless actual_mode == wanted_mode # Check that the file is world-readable.
problem format("Incorrect file permissions (%03<actual>o): chmod %03<wanted>o %<path>s", if actual_mode & 0444 != 0444
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777, actual: actual_mode & 0777,
wanted: wanted_mode & 0777, wanted: "+r",
path: formula.path)
end
# Check that the file is user-writeable.
if actual_mode & 0200 != 0200
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777,
wanted: "u+w",
path: formula.path)
end
# Check that the file is *not* other-writeable.
if actual_mode & 0002 == 002
problem format("Incorrect file permissions (%03<actual>o): chmod %<wanted>s %<path>s",
actual: actual_mode & 0777,
wanted: "o-w",
path: formula.path) path: formula.path)
end end

View File

@ -106,11 +106,40 @@ module Homebrew
RUBY RUBY
path = fa.formula.path path = fa.formula.path
path.chmod 0400
path.chmod 0600
fa.audit_file fa.audit_file
expect(fa.problems) expect(fa.problems)
.to eq(["Incorrect file permissions (400): chmod 644 #{path}"]) .to eq([
"Incorrect file permissions (600): chmod +r #{path}",
])
fa.problems.clear
path.chmod 0444
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (444): chmod u+w #{path}",
])
fa.problems.clear
path.chmod 0646
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (646): chmod o-w #{path}",
])
fa.problems.clear
path.chmod 0002
fa.audit_file
expect(fa.problems)
.to eq([
"Incorrect file permissions (002): chmod +r #{path}",
"Incorrect file permissions (002): chmod u+w #{path}",
"Incorrect file permissions (002): chmod o-w #{path}",
])
fa.problems.clear
end end
specify "DATA but no __END__" do specify "DATA but no __END__" do