Skip to content

Commit 13d261e

Browse files
Ratio2gitster
authored andcommitted
wincred: fix get credential if username has "@"
Such a username with "@" in it isn't all that unusual these days. cf. https://groups.google.com/forum/#!msg/msysgit/YVuCqmwwRyY/HULHj5OoE88J Signed-off-by: Aleksey Vasenev <[email protected]> Acked-by: Erik Faye-Lund <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fdf96a2 commit 13d261e

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

contrib/credential/wincred/git-credential-wincred.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)
111111
* Match an (optional) expected string and a delimiter in the target string,
112112
* consuming the matched text by updating the target pointer.
113113
*/
114-
static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
114+
115+
static LPCWSTR wcsstr_last(LPCWSTR str, LPCWSTR find)
116+
{
117+
LPCWSTR res = NULL, pos;
118+
for (pos = wcsstr(str, find); pos; pos = wcsstr(pos + 1, find))
119+
res = pos;
120+
return res;
121+
}
122+
123+
static int match_part_with_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim, int last)
115124
{
116125
LPCWSTR delim_pos, start = *ptarget;
117126
int len;
118127

119128
/* find start of delimiter (or end-of-string if delim is empty) */
120129
if (*delim)
121-
delim_pos = wcsstr(start, delim);
130+
delim_pos = last ? wcsstr_last(start, delim) : wcsstr(start, delim);
122131
else
123132
delim_pos = start + wcslen(start);
124133

@@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
138147
return !want || (!wcsncmp(want, start, len) && !want[len]);
139148
}
140149

150+
static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
151+
{
152+
return match_part_with_last(ptarget, want, delim, 0);
153+
}
154+
155+
static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
156+
{
157+
return match_part_with_last(ptarget, want, delim, 1);
158+
}
159+
141160
static int match_cred(const CREDENTIALW *cred)
142161
{
143162
LPCWSTR target = cred->TargetName;
@@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)
146165

147166
return match_part(&target, L"git", L":") &&
148167
match_part(&target, protocol, L"://") &&
149-
match_part(&target, wusername, L"@") &&
168+
match_part_last(&target, wusername, L"@") &&
150169
match_part(&target, host, L"/") &&
151170
match_part(&target, path, L"");
152171
}

0 commit comments

Comments
 (0)