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

Re: [RFC PATCH 2/2] reftable: don't memset() a NULL from failed malloc()

From
Han-Wen Nienhuys <hanwen@google.com>
Date
Apr 25, 2022, 10:30 UTC
Message-ID
<CAFQ2z_OF5+BPxchJcydOhE5tPO2DDeuiJ0-5TzN7kTxD7TpEgA@mail.gmail.com>
In-Reply-To
<xmqq1qxyfh8k.fsf@gitster.g>
On Fri, Apr 15, 2022 at 6:23 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
> >> git grep -e 'reftable_[mc]alloc' -e 'reftable_realloc' -A2 origin/master
> >>
> >> and I didn't see a single NULL check
> >
> > I think you're right, I retrieved that information from wetware. Looking
> > again I think I was confusing it with the if (x) free(x) fixes in
> > 34230514b83 (Merge branch 'hn/reftable-coverity-fixes', 2022-02-16).
>
> True.  Initially I hoped that these RFC changes gives us a better
> solution that comes from stepping back and rethinking the issues
> around the original "why are we calling memset() with NULL?", and
memset with NULL is an oversight.

The malloc routines are pluggable so the code could be reused for libgit2. However, as use within Git itself is still not imminent, they could just as well be removed as they are just a premature generalization right now.

> if it were only "well, in _return_block() functions, we clear the
> block before calling _free()---that shouldn't be necessary, if the
> calling custom malloc-free pair cares, they can do the clearing, and
> plain vanilla free() certainly doesn't, so let's stop calling

The memset() calls on free() (eg. in are there to tease out use-after-free bugs in the unittests, but they should probably be removed from file_return_block() as that is production code.

-- 
Han-Wen Nienhuys - Google Munich
I work 80%. Don't expect answers from me on Fridays.
Previous: Junio C HamanoNext: Han-Wen Nienhuys
Message 15 of 16 in “reftable: avoid undefined behaviour breaking t0032”
  1. reftable: avoid undefined behaviour breaking t0032Carlo Marcelo Arenas Belón, Apr 15, 2022
  2. Junio C HamanoApr 15, 2022
  3. reftable: avoid undefined behaviour breaking t0032Carlo Marcelo Arenas Belón, Apr 15, 2022
  4. 0/2 reftable: remove poor man's SANITIZE=address, fix a memset() bugÆvar Arnfjörð Bjarmason, Apr 15, 2022
  5. 1/2 reftable: remove the "return_block" abstractionÆvar Arnfjörð Bjarmason, Apr 15, 2022
  6. René ScharfeApr 15, 2022
  7. Han-Wen NienhuysApr 25, 2022
  8. Junio C HamanoApr 25, 2022
  9. 2/2 reftable: don't memset() a NULL from failed malloc()Ævar Arnfjörð Bjarmason, Apr 15, 2022
  10. René ScharfeApr 15, 2022
  11. Ævar Arnfjörð BjarmasonApr 15, 2022
  12. Phillip WoodApr 15, 2022
  13. Ævar Arnfjörð BjarmasonApr 15, 2022
  14. Junio C HamanoApr 15, 2022
  15. Han-Wen NienhuysApr 25, 2022
  16. Han-Wen NienhuysApr 25, 2022

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.