From d11f41d18b9e1a44254f89c9fac24e63f2ff922f Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 1 Nov 2015 18:29:13 +0100 Subject: [PATCH] git-wrapper: fix interpolation with short values To be precise: when the value of the environment variable is shorter than its name, we have to move the remaining bytes *after* expanding the environment variable: we would look for the wrong name otherwise. When the value is longer than the name, we still need to move the bytes out of the way first, to avoid overwriting them with the interpolated text. This fixes https://github.com/git-for-windows/git/issues/509 Signed-off-by: Johannes Schindelin --- compat/win32/git-wrapper.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compat/win32/git-wrapper.c b/compat/win32/git-wrapper.c index 3b2791b36c..11a574646a 100644 --- a/compat/win32/git-wrapper.c +++ b/compat/win32/git-wrapper.c @@ -269,8 +269,10 @@ static LPWSTR expand_variables(LPWSTR buffer, size_t alloc) if (delta > 0) memmove(atat2 + delta, atat2, move_len); len += delta; - save = atat[env_len - 1]; + save = atat[env_len - 1 + (delta < 0 ? -delta : 0)]; GetEnvironmentVariable(atat + 2, atat, env_len); + if (delta < 0) + memmove(atat2 + delta, atat2, move_len); atat[env_len - 1] = save; }