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

Fix xdg folder permission check for cases when privileges were dropped #4619

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 11 additions & 10 deletions scapy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,18 @@
def _probe_xdg_folder(var, default, *cf):
# type: (str, str, *str) -> Optional[pathlib.Path]
path = pathlib.Path(os.environ.get(var, default))
if not path.exists():
# ~ folder doesn't exist. Create according to spec
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
# "If, when attempting to write a file, the destination directory is
# non-existent an attempt should be made to create it with permission 0700."
try:
try:
if not path.exists():
# ~ folder doesn't exist. Create according to spec
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
# "If, when attempting to write a file, the destination directory is
# non-existent an attempt should be made to create it with permission 0700."
path.mkdir(mode=0o700, exist_ok=True)
except Exception:
# There is a gazillion ways this can fail. Most notably,
# a read-only fs.
return None
except Exception:
# There is a gazillion ways this can fail. Most notably, a read-only fs or no
# permissions to even check for folder to exist (e.x. privileges were dropped
# before scapy was started).
return None
return path.joinpath(*cf).resolve()


Expand Down
Loading