Skip to content

Commit

Permalink
Fix PermissionError: [Errno 13] Permission denied
Browse files Browse the repository at this point in the history
Fix the issue of unclosed files in Windows system causing unauthorized access to read yaml files.

 return yaml.safe_load(file_obj.read_text('utf-8', 'ignore'))
  File "C:\Python3\lib\pathlib.py", line 1266, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
  File "C:\Python3\lib\pathlib.py", line 1252, in open
    return io.open(self, mode, buffering, encoding, errors, newline,
  File "C:\Python3\lib\pathlib.py", line 1120, in _opener
    return self._accessor.open(self, flags, mode)
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\test\\AppData\\Local\\Temp\\tmpclbvrcwq'
  • Loading branch information
ohyeah521 authored Dec 19, 2023
1 parent 1f8c609 commit dbf9b13
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mobsf/StaticAnalyzer/views/android/code_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ def get_perm_rules(perm_rules, android_permissions):
dynamic_rules.append(p)
rules = yaml.dump(dynamic_rules)
if rules:
tmp = tempfile.NamedTemporaryFile(mode='w')
tmp = tempfile.NamedTemporaryFile(mode='w', delete=False)
tmp.write(rules)
tmp.flush()
tmp.close()
return tmp
except Exception:
logger.error('Getting Permission Rules')
Expand Down Expand Up @@ -98,7 +99,10 @@ def code_analysis(app_dir, typ, manifest_file, android_permissions):
[src],
{}))
logger.info('Android Permission Mapping Completed')
rule_file.close()
try:
os.remove(rule_file.name)
except:
pass
# NIAP Scan
niap_findings = niap_scan(
niap_rules.as_posix(),
Expand Down

0 comments on commit dbf9b13

Please sign in to comment.