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

Re: [PATCH] path: use xmalloc in add_to_trie

From
Jeff King <peff@peff.net>
Date
Oct 24, 2017, 19:26 UTC
Message-ID
<20171024192658.4rvxvb34y64lt2tc@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kZM_hVi8BeTmL5u_QK5+=1g3gcPsccEe1AJVpDLUWz_9Q@mail.gmail.com>
On Tue, Oct 24, 2017 at 09:13:28AM -0700, Stefan Beller wrote:
Show 16 quoted lines
> On Tue, Oct 24, 2017 at 8:15 AM, Andrey Okoshkin <a.okoshkin@samsung.com> wrote:
> > Add usage of xmalloc() instead of malloc() in add_to_trie() as xmalloc wraps
> > and checks memory allocation result.
> >
> > Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>
> > ---
> > Hello,
> > I'm not sure but it looks like there is a missing check of the malloc result.
> > memcpy() may crash with SIGSEGV due to the memory allocation failure.
> > make_trie_node() uses xmalloc() and xcalloc() - so I believe add_to_trie()
> > also should use it.
> 
> Good catch! Thanks for spotting.
> 
> Trying to find similar occurrences via git grep "= malloc" did not
> yield other places that need the same fix.

Don't forget realloc and calloc (though I don't think there are any cases that need touching there; just a hint for anybody doing auditing).

-Peff
Previous: Stefan Beller
Message 3 of 3 in “path: use xmalloc in add_to_trie”
  1. path: use xmalloc in add_to_trieAndrey Okoshkin, Oct 24, 2017
  2. Stefan BellerOct 24, 2017
  3. Jeff KingOct 24, 2017

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.