Skip to content

Commit 80f3b38

Browse files
fix: handle permission and not found errors when checking file mode
1 parent 182d02c commit 80f3b38

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s3cmd

S3/Config.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -642,13 +642,16 @@ def __init__(self, file, sections = []):
642642

643643
def parse_file(self, file, sections = []):
644644
debug("ConfigParser: Reading file '%s'" % file)
645-
file_mode = os.stat(file).st_mode
646-
is_group_readable = bool(file_mode & stat.S_IRGRP)
647-
is_world_readable = bool(file_mode & stat.S_IROTH)
648-
if is_group_readable:
649-
warning(f"s3cmd configuration file is group-readable. This is insecure. Location: {file}")
650-
if is_world_readable:
651-
warning(f"s3cmd configuration file is world-readable. This is insecure. Location: {file}")
645+
try:
646+
file_mode = os.stat(file).st_mode
647+
is_group_readable = bool(file_mode & stat.S_IRGRP)
648+
is_world_readable = bool(file_mode & stat.S_IROTH)
649+
if is_group_readable:
650+
warning(f"s3cmd configuration file is group-readable. This is insecure. Location: {file}")
651+
if is_world_readable:
652+
warning(f"s3cmd configuration file is world-readable. This is insecure. Location: {file}")
653+
except (FileNotFoundError, PermissionError):
654+
pass
652655
if type(sections) != type([]):
653656
sections = [sections]
654657
in_our_section = True

0 commit comments

Comments
 (0)