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 <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2015-11-01 18:29:13 +01:00
parent c885439682
commit 3006781534

View File

@@ -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;
}