Skip to content

Commit

Permalink
Merge pull request #268 from TrellixVulnTeam/master
Browse files Browse the repository at this point in the history
  • Loading branch information
leeping committed Feb 4, 2023
2 parents ea1e746 + ad1bfcd commit 41b9b73
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,23 @@ def read(self,mvals,AGrad=False,AHess=False):

def get(self,mvals,AGrad=False,AHess=False):
with tarfile.open("target_result.tar.bz2", "r") as tar:
tar.extractall()
# Added by vulnerability checker to guard against directory traversal attack
def is_within_directory(directory, target):
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
prefix = os.path.commonprefix([abs_directory, abs_target])
return prefix == abs_directory

def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")
tar.extractall(path, members, numeric_owner=numeric_owner)

safe_extract(tar)
# Remove the target_result archive as it's not needed anymore.
os.unlink("target_result.tar.bz2")
with open('indicate.log', 'r') as f:
self.remote_indicate = f.read()
return lp_load('objective.p')
Expand Down

0 comments on commit 41b9b73

Please sign in to comment.