Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

CVE-2007-4559 Patch #53

Closed
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
42 changes: 40 additions & 2 deletions tools/proto_format/format_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,50 @@ def format_api(mode, outfile, xformed, printed):
printed_dir = dst_dir.joinpath("printed")
printed_dir.mkdir()
with tarfile.open(printed) as tar:
tar.extractall(printed_dir)
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, printed_dir)

xformed_dir = dst_dir.joinpath("xformed")
xformed_dir.mkdir()
with tarfile.open(xformed) as tar:
tar.extractall(xformed_dir)
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, xformed_dir)

paths = []
dst_src_paths = defaultdict(list)
Expand Down
21 changes: 20 additions & 1 deletion tools/proto_format/proto_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,26 @@ def sync(api_root, formatted, mode, is_ci):
# b - ideally formatted version of api directory according to bazel
dst_dir = tmp_path.joinpath("b")
with tarfile.open(formatted) as tar:
tar.extractall(dst_dir)
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, dst_dir)

# These support files are handled manually.
for f in ['envoy/annotations/resource.proto', 'envoy/annotations/deprecation.proto',
Expand Down
42 changes: 40 additions & 2 deletions tools/protoprint/protoprint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,47 @@ def main():
golden = tmp.joinpath("golden")

with tarfile.open(parsed.formatted) as tar:
tar.extractall(formatted)
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, formatted)
with tarfile.open(parsed.golden) as tar:
tar.extractall(golden)
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, golden)

os.chdir(PATH)

Expand Down