From: Junio C Hamano <gitster@pobox.com>
To: Shlok Kulshreshtha <diy2903@gmail.com>
Cc: git@vger.kernel.org, l.s.r@web.de, Johannes.Schindelin@gmx.de,
ps@pks.im
Subject: Re: [PATCH v3] object-name: avoid use-after-free in get_oid_with_context_1()
Date: Mon, 17 Aug 2026 08:43:57 -0700 [thread overview]
Message-ID: <xmqq1pbw7nwi.fsf@gitster.g> (raw)
In-Reply-To: <20260817082127.81132-1-diy2903@gmail.com> (Shlok Kulshreshtha's message of "Mon, 17 Aug 2026 13:51:27 +0530")
Shlok Kulshreshtha <diy2903@gmail.com> writes:
> When a ":<path>" argument names a relative path, resolve_relative_path()
> returns a newly allocated string and "cp" is pointed at it:
>
> new_path = resolve_relative_path(repo, cp);
> if (!new_path) {
> namelen = namelen - (cp - name);
> } else {
> cp = new_path;
> namelen = strlen(cp);
> }
>
> From there on "cp" and "new_path" name the same allocation. Later the
> memory location that "new_path" points to is freed.
>
> free(new_path);
> if (reject_tree_in_index(repo, only_to_die, ce, stage, prefix, cp))
Nicely described and ...
> diff --git a/object-name.c b/object-name.c
> index 83efba0ba6..026ff8c6dd 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -1803,13 +1803,15 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
> memcmp(ce->name, cp, namelen))
> break;
> if (ce_stage(ce) == stage) {
> + int ret = reject_tree_in_index(repo, only_to_die, ce,
> + stage, prefix, cp);
> +
> + if (!ret) {
> + oidcpy(oid, &ce->oid);
> + oc->mode = ce->ce_mode;
> + }
> free(new_path);
> - if (reject_tree_in_index(repo, only_to_die, ce,
> - stage, prefix, cp))
> - return -1;
> - oidcpy(oid, &ce->oid);
> - oc->mode = ce->ce_mode;
> - return 0;
> + return ret;
> }
... the fix matches exactly what anybody would expect from the
problem description, i.e., "Do not free new_path before we are done
with using cp".
Will queue. Thanks.
next prev parent reply other threads:[~2026-08-17 15:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 19:59 [PATCH] object-name: avoid use-after-free in get_oid_with_context_1() Shlok Kulshreshtha
2026-08-08 16:23 ` René Scharfe
2026-08-08 20:08 ` Shlok Kulshreshtha
2026-08-09 19:42 ` [PATCH v2] " Shlok Kulshreshtha
2026-08-10 6:17 ` Patrick Steinhardt
2026-08-17 8:21 ` [PATCH v3] " Shlok Kulshreshtha
2026-08-17 15:43 ` Junio C Hamano [this message]
2026-08-17 8:32 ` [PATCH v2] " Shlok Kulshreshtha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq1pbw7nwi.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=diy2903@gmail.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.