Skip to content

Commit

Permalink
builtin_diff(): read $GIT_DIFF_OPTS closer to use
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and dscho committed Jan 17, 2019
1 parent 69cbeaa commit cb62289
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -3476,7 +3476,7 @@ static void builtin_diff(const char *name_a,
o->found_changes = 1;
} else {
/* Crazy xdl interfaces.. */
const char *diffopts = getenv("GIT_DIFF_OPTS");
const char *diffopts;
const char *v;
xpparam_t xpp;
xdemitconf_t xecfg;
Expand Down Expand Up @@ -3519,12 +3519,15 @@ static void builtin_diff(const char *name_a,
xecfg.flags |= XDL_EMIT_FUNCCONTEXT;
if (pe)
xdiff_set_find_func(&xecfg, pe->pattern, pe->cflags);

diffopts = getenv("GIT_DIFF_OPTS");
if (!diffopts)
;
else if (skip_prefix(diffopts, "--unified=", &v))
xecfg.ctxlen = strtoul(v, NULL, 10);
else if (skip_prefix(diffopts, "-u", &v))
xecfg.ctxlen = strtoul(v, NULL, 10);

if (o->word_diff)
init_diff_words_data(&ecbdata, o, one, two);
if (xdi_diff_outf(&mf1, &mf2, NULL, fn_out_consume,
Expand Down

0 comments on commit cb62289

Please sign in to comment.