Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fuzzing: Fix Broken Fuzz Test for Git Submodule Handling#1997

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Changes fromall 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
59 changes: 42 additions & 17 deletionsfuzzing/fuzz-targets/fuzz_submodule.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,11 +9,17 @@
get_max_filename_length,
)

# Setup thegit environment
# Setup theGit environment
setup_git_environment()
fromgitimportRepo,GitCommandError,InvalidGitRepositoryError


defsanitize_input(input_str,max_length=255):
"""Sanitize and truncate inputs to avoid invalid Git operations."""
sanitized="".join(chforchininput_strifch.isalnum()orchin ("-","_","."))
returnsanitized[:max_length]


defTestOneInput(data):
fdp=atheris.FuzzedDataProvider(data)

Expand All@@ -24,12 +30,23 @@ def TestOneInput(data):
try:
withtempfile.TemporaryDirectory()assubmodule_temp_dir:
sub_repo=Repo.init(submodule_temp_dir,bare=fdp.ConsumeBool())
sub_repo.index.commit(fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1,512)))
commit_message=sanitize_input(fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(1,512)))
sub_repo.index.commit(commit_message)

submodule_name=fdp.ConsumeUnicodeNoSurrogates(
fdp.ConsumeIntInRange(1,max(1,get_max_filename_length(repo.working_tree_dir)))
submodule_name=sanitize_input(
fdp.ConsumeUnicodeNoSurrogates(
fdp.ConsumeIntInRange(1,get_max_filename_length(repo.working_tree_dir))
)
)
submodule_path=os.path.join(repo.working_tree_dir,submodule_name)

submodule_path=os.path.relpath(
os.path.join(repo.working_tree_dir,submodule_name),
start=repo.working_tree_dir,
)

# Ensure submodule_path is valid
ifnotsubmodule_nameorsubmodule_name.startswith("/")or".."insubmodule_name:
return-1# Reject invalid input so they are not added to the corpus

submodule=repo.create_submodule(submodule_name,submodule_path,url=sub_repo.git_dir)
repo.index.commit("Added submodule")
Expand All@@ -39,25 +56,38 @@ def TestOneInput(data):
value_length=fdp.ConsumeIntInRange(1,max(1,fdp.remaining_bytes()))

writer.set_value(
fdp.ConsumeUnicodeNoSurrogates(key_length),fdp.ConsumeUnicodeNoSurrogates(value_length)
sanitize_input(fdp.ConsumeUnicodeNoSurrogates(key_length)),
sanitize_input(fdp.ConsumeUnicodeNoSurrogates(value_length)),
)
writer.release()

submodule.update(init=fdp.ConsumeBool(),dry_run=fdp.ConsumeBool(),force=fdp.ConsumeBool())
submodule.update(
init=fdp.ConsumeBool(),
dry_run=fdp.ConsumeBool(),
force=fdp.ConsumeBool(),
)

submodule_repo=submodule.module()

new_file_name=fdp.ConsumeUnicodeNoSurrogates(
fdp.ConsumeIntInRange(1,max(1,get_max_filename_length(submodule_repo.working_tree_dir)))
new_file_name=sanitize_input(
fdp.ConsumeUnicodeNoSurrogates(
fdp.ConsumeIntInRange(1,get_max_filename_length(submodule_repo.working_tree_dir))
)
)
new_file_path=os.path.join(submodule_repo.working_tree_dir,new_file_name)
withopen(new_file_path,"wb")asnew_file:
new_file.write(fdp.ConsumeBytes(fdp.ConsumeIntInRange(1,512)))

submodule_repo.index.add([new_file_path])
submodule_repo.index.commit("Added new file to submodule")

repo.submodule_update(recursive=fdp.ConsumeBool())
submodule_repo.head.reset(commit="HEAD~1",working_tree=fdp.ConsumeBool(),head=fdp.ConsumeBool())
# Use fdp.PickValueInList to ensure at least one of 'module' or 'configuration' is True
submodule_repo.head.reset(
commit="HEAD~1",
working_tree=fdp.ConsumeBool(),
head=fdp.ConsumeBool(),
)

module_option_value,configuration_option_value=fdp.PickValueInList(
[(True,False), (False,True), (True,True)]
)
Expand All@@ -82,12 +112,7 @@ def TestOneInput(data):
):
return-1
exceptExceptionase:
ifisinstance(e,ValueError)and"embedded null byte"instr(e):
return-1
elifisinstance(e,OSError)and"File name too long"instr(e):
return-1
else:
returnhandle_exception(e)
returnhandle_exception(e)


defmain():
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp