Skip to content

Commit

Permalink
git-wrapper: fix interpolation with short values
Browse files Browse the repository at this point in the history
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 git-for-windows#509

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Nov 7, 2015
1 parent 9e45a79 commit 15fc2c1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compat/win32/git-wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 15fc2c1

Please sign in to comment.