Skip to content

Commit cb62289

Browse files
peffdscho
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 69cbeaa commit cb62289

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
@@ -3476,7 +3476,7 @@ static void builtin_diff(const char *name_a,
34763476
o->found_changes = 1;
34773477
} else {
34783478
/* Crazy xdl interfaces.. */
3479-
const char *diffopts = getenv("GIT_DIFF_OPTS");
3479+
const char *diffopts;
34803480
const char *v;
34813481
xpparam_t xpp;
34823482
xdemitconf_t xecfg;
@@ -3519,12 +3519,15 @@ static void builtin_diff(const char *name_a,
35193519
xecfg.flags |= XDL_EMIT_FUNCCONTEXT;
35203520
if (pe)
35213521
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);
3522+
3523+
diffopts = getenv("GIT_DIFF_OPTS");
35223524
if (!diffopts)
35233525
;
35243526
else if (skip_prefix(diffopts, "--unified=", &v))
35253527
xecfg.ctxlen = strtoul(v, NULL, 10);
35263528
else if (skip_prefix(diffopts, "-u", &v))
35273529
xecfg.ctxlen = strtoul(v, NULL, 10);
3530+
35283531
if (o->word_diff)
35293532
init_diff_words_data(&ecbdata, o, one, two);
35303533
if (xdi_diff_outf(&mf1, &mf2, NULL, fn_out_consume,

0 commit comments

Comments
 (0)