banned-die: create header for banning of functions

We have universally-banned functions listed in banned.h since
c8af66ab8a (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.

It would be reasonable to name this file trace2/tr2_banned.h to be
specific to the trace2 API, but it seems like such a restriction would
be valuable to put in some other areas of the code, so adding it at the
root of the tree seems like a good long-term approach.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
seen
Derrick Stolee 2026-08-31 17:25:37 +00:00 committed by Junio C Hamano
parent c73e85354c
commit e5a7126918
14 changed files with 40 additions and 0 deletions

14
banned-die.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef BANNED_DIE_H
#define BANNED_DIE_H

#include "banned.h"

/*
* This header lists functions that must not be used by low-level APIs
* because they can cause Git to terminate.
*/

#undef die
#define die BANNED(die)

#endif /* BANNED_DIE_H */

View File

@ -17,6 +17,8 @@
#include "trace2/tr2_tgt.h" #include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_tmr.h" #include "trace2/tr2_tmr.h"
/* banned-die must be last. */
#include "banned-die.h"


static int trace2_enabled; static int trace2_enabled;
static int trace2_redact = 1; static int trace2_redact = 1;

View File

@ -7,6 +7,8 @@
#include "trace2/tr2_cfg.h" #include "trace2/tr2_cfg.h"
#include "trace2/tr2_sysenv.h" #include "trace2/tr2_sysenv.h"
#include "wildmatch.h" #include "wildmatch.h"
/* banned-die must be last. */
#include "banned-die.h"


static struct string_list tr2_cfg_patterns = STRING_LIST_INIT_DUP; static struct string_list tr2_cfg_patterns = STRING_LIST_INIT_DUP;
static int tr2_cfg_loaded; static int tr2_cfg_loaded;

View File

@ -1,6 +1,8 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "strbuf.h" #include "strbuf.h"
#include "trace2/tr2_cmd_name.h" #include "trace2/tr2_cmd_name.h"
/* banned-die must be last. */
#include "banned-die.h"


#define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME" #define TR2_ENVVAR_PARENT_NAME "GIT_TRACE2_PARENT_NAME"



View File

@ -2,6 +2,8 @@
#include "trace2/tr2_tgt.h" #include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_ctr.h" #include "trace2/tr2_ctr.h"
/* banned-die must be last. */
#include "banned-die.h"


/* /*
* A global counter block to aggregate values from the partial sums * A global counter block to aggregate values from the partial sums

View File

@ -5,6 +5,8 @@
#include "trace2/tr2_dst.h" #include "trace2/tr2_dst.h"
#include "trace2/tr2_sid.h" #include "trace2/tr2_sid.h"
#include "trace2/tr2_sysenv.h" #include "trace2/tr2_sysenv.h"
/* banned-die must be last. */
#include "banned-die.h"


/* /*
* How many attempts we will make at creating an automatically-named trace file. * How many attempts we will make at creating an automatically-named trace file.

View File

@ -3,6 +3,8 @@
#include "strbuf.h" #include "strbuf.h"
#include "trace2/tr2_tbuf.h" #include "trace2/tr2_tbuf.h"
#include "trace2/tr2_sid.h" #include "trace2/tr2_sid.h"
/* banned-die must be last. */
#include "banned-die.h"


#define TR2_ENVVAR_PARENT_SID "GIT_TRACE2_PARENT_SID" #define TR2_ENVVAR_PARENT_SID "GIT_TRACE2_PARENT_SID"



View File

@ -4,6 +4,8 @@
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"
#include "tr2_sysenv.h" #include "tr2_sysenv.h"
/* banned-die must be last. */
#include "banned-die.h"


/* /*
* Each entry represents a trace2 setting. * Each entry represents a trace2 setting.

View File

@ -1,5 +1,7 @@
#include "git-compat-util.h" #include "git-compat-util.h"
#include "tr2_tbuf.h" #include "tr2_tbuf.h"
/* banned-die must be last. */
#include "banned-die.h"


void tr2_tbuf_local_time(struct tr2_tbuf *tb) void tr2_tbuf_local_time(struct tr2_tbuf *tb)
{ {

View File

@ -13,6 +13,8 @@
#include "trace2/tr2_tgt.h" #include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_tmr.h" #include "trace2/tr2_tmr.h"
/* banned-die must be last. */
#include "banned-die.h"


static struct tr2_dst tr2dst_event = { static struct tr2_dst tr2dst_event = {
.sysenv_var = TR2_SYSENV_EVENT, .sysenv_var = TR2_SYSENV_EVENT,

View File

@ -11,6 +11,8 @@
#include "trace2/tr2_tgt.h" #include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_tmr.h" #include "trace2/tr2_tmr.h"
/* banned-die must be last. */
#include "banned-die.h"


static struct tr2_dst tr2dst_normal = { static struct tr2_dst tr2dst_normal = {
.sysenv_var = TR2_SYSENV_NORMAL, .sysenv_var = TR2_SYSENV_NORMAL,

View File

@ -14,6 +14,8 @@
#include "trace2/tr2_tgt.h" #include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_tmr.h" #include "trace2/tr2_tmr.h"
/* banned-die must be last. */
#include "banned-die.h"


static struct tr2_dst tr2dst_perf = { static struct tr2_dst tr2dst_perf = {
.sysenv_var = TR2_SYSENV_PERF, .sysenv_var = TR2_SYSENV_PERF,

View File

@ -3,6 +3,8 @@
#include "thread-utils.h" #include "thread-utils.h"
#include "trace.h" #include "trace.h"
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
/* banned-die must be last. */
#include "banned-die.h"


/* /*
* Initialize size of the thread stack for nested regions. * Initialize size of the thread stack for nested regions.

View File

@ -3,6 +3,8 @@
#include "trace2/tr2_tls.h" #include "trace2/tr2_tls.h"
#include "trace2/tr2_tmr.h" #include "trace2/tr2_tmr.h"
#include "trace.h" #include "trace.h"
/* banned-die must be last. */
#include "banned-die.h"


#define MY_MAX(a, b) ((a) > (b) ? (a) : (b)) #define MY_MAX(a, b) ((a) > (b) ? (a) : (b))
#define MY_MIN(a, b) ((a) < (b) ? (a) : (b)) #define MY_MIN(a, b) ((a) < (b) ? (a) : (b))