From: Jeff King Date: Fri, 11 Jan 2019 22:17:22 +0000 (-0500) Subject: builtin_diff(): read $GIT_DIFF_OPTS closer to use X-Git-Tag: v2.21.0-rc0~69^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/0da0e9268b4825cafb27bb0e07b43fae30bb33da 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 Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index db5e5e9640..0920b12c0c 100644 --- a/diff.c +++ b/diff.c @@ -3444,7 +3444,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; @@ -3487,12 +3487,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, fn_out_consume, &ecbdata,