Skip to content

Commit 0da0e92

Browse files
peffgitster
authored andcommitted
builtin_diff(): read $GIT_DIFF_OPTS closer to use
The value returned by getenv() is not guaranteed to remain valid across other environment function calls. But in between our call and using the value, we run fill_textconv(), which may do quite a bit of work, including spawning sub-processes. We can make this safer by calling getenv() right before we actually look at its value. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d64bb06 commit 0da0e92

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

diff.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,7 @@ static void builtin_diff(const char *name_a,
34443444
o->found_changes = 1;
34453445
} else {
34463446
/* Crazy xdl interfaces.. */
3447-
const char *diffopts = getenv("GIT_DIFF_OPTS");
3447+
const char *diffopts;
34483448
const char *v;
34493449
xpparam_t xpp;
34503450
xdemitconf_t xecfg;
@@ -3487,12 +3487,15 @@ static void builtin_diff(const char *name_a,
34873487
xecfg.flags |= XDL_EMIT_FUNCCONTEXT;
34883488
if (pe)
34893489
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
3490+
3491+
diffopts = getenv("GIT_DIFF_OPTS");
34903492
if (!diffopts)
34913493
;
34923494
else if (skip_prefix(diffopts, "--unified=", &v))
34933495
xecfg.ctxlen = strtoul(v, NULL, 10);
34943496
else if (skip_prefix(diffopts, "-u", &v))
34953497
xecfg.ctxlen = strtoul(v, NULL, 10);
3498+
34963499
if (o->word_diff)
34973500
init_diff_words_data(&ecbdata, o, one, two);
34983501
if (xdi_diff_outf(&mf1, &mf2, fn_out_consume, &ecbdata,

0 commit comments

Comments
 (0)