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

Updated vectorscan pre-compilation to respect umask when writing database files #248

Merged
merged 1 commit into from
May 15, 2024
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
2 changes: 2 additions & 0 deletions wordfence/cli/malwarescan/malwarescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from wordfence.util.platform import Platform, UnknownPlatform
from wordfence.intel.signatures import SignatureSet, PrecompiledSignatureSet, \
deserialize_precompiled_signature_set
from wordfence.util.io import chmod_with_umask
from wordfence.logging import (log, remove_initial_handler,
restore_initial_handler)
from ..subcommands import Subcommand
Expand Down Expand Up @@ -262,6 +263,7 @@ def filter_precompiled(precompiled):
file.write(pickle.dumps(precompiled))
file.flush()
file.close()
chmod_with_umask(file.name)
os.replace(file.name, database_path)

if precompiled is None:
Expand Down
1 change: 1 addition & 0 deletions wordfence/intel/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def deserialize_precompiled_signature_set(data):
signature_set = limited_deserialize(
data,
{
'wordfence.api.licensing.License',
'wordfence.intel.signatures.PrecompiledSignatureSet',
'wordfence.intel.signatures.SignatureSet',
'wordfence.intel.signatures.Signature',
Expand Down
16 changes: 16 additions & 0 deletions wordfence/util/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,19 @@ def iterate_files(
yield from iterate_files(item.path, parents, loop_callback)
else:
yield item.path


def get_umask() -> int:
current = os.umask(0)
os.umask(current)
return current


def umask_mode(mode: int) -> int:
umask = get_umask()
return mode & ~umask


def chmod_with_umask(path: str, mode: int = 0o666) -> int:
mode = umask_mode(mode)
os.chmod(path, mode)
Loading