Skip to content

refspec: guard the wildcard check against an empty source - #7499

Open
arpitjain099 wants to merge 1 commit into
libgit2:mainfrom
arpitjain099:fix/refspec-empty-src-wildcard
Open

arpitjain099 wants to merge 1 commit into
libgit2:mainfrom
arpitjain099:fix/refspec-empty-src-wildcard

Conversation

@arpitjain099

Copy link
Copy Markdown

git_refspec_is_wildcard decides whether a refspec is a pattern by reading
spec->src[strlen(spec->src) - 1]. An empty left hand side is accepted on a fetch refspec, the
parser's own comment being "empty is allowed; it means HEAD", and the suite already asserts that
:refs/remotes/frotz/HEAD-to-me is valid. So src can be "", the index is then (size_t)-1,
and AddressSanitizer reports a one byte read before the git__strndup allocation that
git_refspec__parse made.

It is reachable from git_remote_fetch. With a refspec of :refs/remotes/origin/head-to-me and
download_tags set to all, update_tips_for_spec collects the remote tag heads and
git_remote_write_fetchhead then asks whether the spec is a wildcard. The parser guards the
equivalent look at the lhs with 1 <= llen before scanning for a *, so the helper should do the
same.

The added test hits the over-read under ASan without the change and passes with it.

Prepared with AI assistance.

git_refspec_is_wildcard reads spec->src[strlen(spec->src) - 1]. An empty left
hand side is accepted on a fetch refspec, so src can be "" and the index is
then (size_t)-1, which reads one byte before the allocation that
git_refspec__parse made. AddressSanitizer reports it as a heap buffer
over-read on the path from git_remote_fetch through
git_remote_write_fetchhead.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant