git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fix null pointer dereference

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Mar 21, 2021, 12:43 UTC
Message-ID
<87tup4r81k.fsf@evledraar.gmail.com>
In-Reply-To
<pull.983.git.git.1616323936790.gitgitgadget@gmail.com>
On Sun, Mar 21 2021, Kleber Tarcísio via GitGitGadget wrote:
Show 19 quoted lines
> From: =?UTF-8?q?Kleber=20Tarc=C3=ADsio?= <klebertarcisio@yahoo.com.br>
>
> The malloc function can return null when the memory allocation fails. This commit adds a condition to handle these cases properly. https://cwe.mitre.org/data/definitions/476.html
>
> Signed-off-by: Kleber Tarcísio <klebertarcisio@yahoo.com.br>
> ---
>     Avoiding null pointer dereference
>     
>     This pull request aims to fix null pointer dereference.
>     
>     Null pointer dereference
>     [https://cwe.mitre.org/data/definitions/476.html]
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-983%2Fklebertarcisio%2Fpatch-1-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-983/klebertarcisio/patch-1-v1
> Pull-Request: https://github.com/git/git/pull/983
>
>  builtin/submodule--helper.c | 2 ++
>  1 file changed, 2 insertions(+)

Thanks, from my brief grepping of the remaining code in git.git there is no other malloc() that doesn't have its return value checked appropriately.

Show 13 quoted lines
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index 9d505a6329c8..92349d715a78 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1215,6 +1215,8 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
>  		if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
>  			continue;
>  		temp = (struct module_cb*)malloc(sizeof(struct module_cb));
> +		if (!temp) 
> +			die(_("out of memory"));
>  		temp->mod_src = p->one->mode;
>  		temp->mod_dst = p->two->mode;
>  		temp->oid_src = p->one->oid;

When we just want to die if we can't allocate memory we should use the xmalloc() wrapper instead.

Previous: Kleber Tarcísio via GitGitGadgetNext: Matheus Tavares Bernardino
Message 2 of 4 in “fix null pointer dereference”
  1. fix null pointer dereferenceKleber Tarcísio via GitGitGadget, Mar 21, 2021
  2. Ævar Arnfjörð BjarmasonMar 21, 2021
  3. Matheus Tavares BernardinoMar 21, 2021
  4. Junio C HamanoMar 21, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.