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

Re: [PATCH v2 1/7] banned-die: create header for banning of functions

From
Derrick Stolee <stolee@gmail.com>
Date
Aug 31, 2026, 12:38 UTC
Message-ID
<9a84da3f-3409-49ea-be57-1e17e373273c@gmail.com>
In-Reply-To
<20260827051053.GB176544@coredump.intra.peff.net>
On 8/27/2026 1:10 AM, Jeff King wrote:
Show 25 quoted lines
> On Tue, Aug 25, 2026 at 06:56:15PM +0000, Derrick Stolee via GitGitGadget wrote:
> 
>> We have universally-banned functions listed in banned.h since
>> c8af66ab8ad (automatically ban strcpy(), 2018-07-26), but some layers of
>> the code should be more strict than others.
>>
>> One such example is the trace2 API which runs during atexit() and can
>> prove to cause die()-handler recursion problems if it calls die().
>>
>> Create a new banned-die.h header file that will ban some Git methods
>> that call die(). Include that in all trace2 API implementation files.
>> This currently only bans die() itself, and that was already not used.
> 
> There's a subtle but big difference between the universal code bans in
> banned.h and this banned-die.h. In the former case we are deciding
> strcpy() is unfit for our code base and outlawing it everywhere. The
> potential problem is in the source code, so catching it while compiling
> the source code is OK.
> 
> But we are not doing that with die(). It is a perfectly OK function in
> general, but we do not want to ever trigger its runtime effects from
> certain code paths. Banning it from being called from those code paths
> can catch _some_ instances, but not any transitive calls. If we call
> foo(), it may call die() itself, and we would not want to ban foo() from
> doing so. And recursively for functions called by foo() and so on.

Yes, this makes it tricky to be 100% sure without some kind of static analysis.

> So you end up playing whack-a-mole with functions that might call die()
> and adding them to this ban list.

This does have some benefit that we can gradually remove these transitive callers in the multi-commit series. But it's unsatisfying as a full protection in the end.

Show 11 quoted lines
> I think that's _probably_ the best we can do in practice. I think the
> framing above suggests that we could approach the problem more directly
> with a runtime flag: when we enter those code paths, set a flag to avoid
> the unwanted behavior, and have the low-level code respect that. But
> die() is a special case here, because we'd want to suppress its
> no-return behavior. And its callers are not prepared for die() to
> suddenly start returning because of some global flag.
> 
> So I think the whack-a-mole is the best we can do. But I would not want
> to see this strategy extended to other areas. In most cases some kind of
> runtime support is probably a better solution.

The other alternative that we could consider is to reorganize the codebase in such a way that certain sections of code don't have access to headers that could lead to die() or other "higher" methods that are acceptable for user-facing processes but are best to avoid in library APIs. Even then, we'd need some checks at compile time to avoid crossing boundaries.

I don't think such a reorganization is desirable overall, because that will be very disruptive to the project and file history.

Having some amount of protection through this header gives us a mechanism to demonstrate and enforce some protection.

Thanks, -Stolee

Previous: Jeff KingNext: Derrick Stolee via GitGitGadget
Message 17 of 43 in “trace2: tolerate failed timestamp formatting”
  1. trace2: tolerate failed timestamp formattingDerrick Stolee via GitGitGadget, Jul 15, 2026
  2. Taylor BlauJul 17, 2026
  3. Derrick StoleeJul 18, 2026
  4. Junio C HamanoJul 20, 2026
  5. Taylor BlauJul 20, 2026
  6. Junio C HamanoJul 29, 2026
  7. Derrick StoleeJul 31, 2026
  8. Junio C HamanoJul 31, 2026
  9. 0/7 trace2: stop allowing die()Derrick Stolee via GitGitGadget, Aug 25, 2026
  10. 1/7 banned-die: create header for banning of functionsDerrick Stolee via GitGitGadget, Aug 25, 2026
  11. Junio C HamanoAug 25, 2026
  12. Derrick StoleeAug 31, 2026
  13. Patrick SteinhardtAug 31, 2026
  14. Elijah NewrenAug 25, 2026
  15. Derrick StoleeAug 31, 2026
  16. Jeff KingAug 27, 2026
  17. Derrick StoleeAug 31, 2026
  18. 2/7 trace2: tolerate failed timestamp formattingDerrick Stolee via GitGitGadget, Aug 25, 2026
  19. 3/7 trace2: remove use of xstrdup()Derrick Stolee via GitGitGadget, Aug 25, 2026
  20. Elijah NewrenAug 25, 2026
  21. Derrick StoleeAug 31, 2026
  22. 4/7 trace2: remove use of ALLOC_ARRAY()Derrick Stolee via GitGitGadget, Aug 25, 2026
  23. 5/7 trace2: remove use of xstrfmt()Derrick Stolee via GitGitGadget, Aug 25, 2026
  24. Elijah NewrenAug 25, 2026
  25. Junio C HamanoAug 25, 2026
  26. Derrick StoleeAug 31, 2026
  27. 6/7 trace2: remove use of ALLOC_GROW()Derrick Stolee via GitGitGadget, Aug 25, 2026
  28. Elijah NewrenAug 25, 2026
  29. 7/7 trace2: remove use of xcalloc()Derrick Stolee via GitGitGadget, Aug 25, 2026
  30. Jeff KingAug 27, 2026
  31. Derrick StoleeAug 31, 2026
  32. Jeff KingSep 1, 2026
  33. Jeff KingSep 1, 2026
  34. Derrick StoleeSep 1, 2026
  35. 0/7 trace2: stop allowing die()Derrick Stolee via GitGitGadget, Aug 31, 2026
  36. 1/7 banned-die: create header for banning of functionsDerrick Stolee via GitGitGadget, Aug 31, 2026
  37. 2/7 trace2: tolerate failed timestamp formattingDerrick Stolee via GitGitGadget, Aug 31, 2026
  38. 3/7 trace2: remove use of xstrdup()Derrick Stolee via GitGitGadget, Aug 31, 2026
  39. 4/7 trace2: remove use of ALLOC_ARRAY()Derrick Stolee via GitGitGadget, Aug 31, 2026
  40. 5/7 trace2: remove use of xstrfmt()Derrick Stolee via GitGitGadget, Aug 31, 2026
  41. 6/7 trace2: remove use of ALLOC_GROW()Derrick Stolee via GitGitGadget, Aug 31, 2026
  42. 7/7 trace2: remove use of xcalloc()Derrick Stolee via GitGitGadget, Aug 31, 2026
  43. Derrick StoleeOct 6, 2026

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.