Re: Potential Null Pointer Dereference detected by static analysis tool
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Aug 13, 2025, 13:19 UTC
- Message-ID
- <5303c45e-d95b-4bc8-9cd1-bf4efe6bfbae@gmail.com>
- In-Reply-To
- <AAkArwD3JXZP4EIjvKF0Waow.1.1755044612233.Hmail.2201111603@stu.pku.edu.cn>
Hi Cheng
On 13/08/2025 01:23, Cheng wrote:
Show 20 quoted lines
> > > line 326 in builtin/describe.cdescribe.c, which is located in the function describe_commit. In the following code, cmit could be NULL passed to the call, which then causes a NULL dereference. Seems should be replaced lookup_commit_reference with lookup_commit_or_die. > > > ```cpp > cmit = lookup_commit_reference(the_repository, oid); > n = find_commit_name(&cmit->object.oid); > ``` > > > > The NULL value seems to come from function lookup_commit_reference_gently where: > > - 1. call to deref_tag may return NULL. > > - 2. call to object_as_type may return NULL. > > > In this repository, other calls lookup_commit_reference are followed by a null check. So this seems to lead to NULL dereference. Can I confirm with you whether this is a true positive bug report?
I had a quick look at the callers of describe_commit() and they all seem to use an oid that they get from looking up a commit so I'm not sure under what circumstances this call to lookup_commit_reference() can fail.
Thanks
Phillip