{"thread":{"id":"37946","subject":"[PATCH] wincred: fix get credential if username has @","startedAt":"2014-11-12T22:52:26Z","lastAt":"2015-01-26T04:25:53Z","messageCount":5,"participants":["Aleksey Vasenev","Junio C Hamano","Erik Faye-Lund"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"251782","messageId":"1415832746-5116-1-git-send-email-margtu-fivt@ya.ru","threadId":"37946","inReplyTo":null,"subject":"[PATCH] wincred: fix get credential if username has @","fromName":"Aleksey Vasenev","fromEmail":"margtu-fivt@ya.ru","sentAt":"2014-11-12T22:52:26Z","receivedAt":"2014-11-12T22:52:26Z","isPatch":true,"sender":{"key":"margtu-fivt@ya.ru","avatar":"https://avatars.githubusercontent.com/u/2958497?v=4"},"body":"Signed-off-by: Aleksey Vasenev <margtu-fivt@ya.ru>\n---\n .../credential/wincred/git-credential-wincred.c    | 25 +++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\nindex a1d38f0..0229443 100644\n--- a/contrib/credential/wincred/git-credential-wincred.c\n+++ b/contrib/credential/wincred/git-credential-wincred.c\n@@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n  * Match an (optional) expected string and a delimiter in the target string,\n  * consuming the matched text by updating the target pointer.\n  */\n-static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+\n+LPCWSTR wcsstr_last(LPCWSTR str, LPCWSTR find)\n+{\n+\tLPCWSTR res = NULL, pos;\n+\tfor (pos = wcsstr(str, find); pos; pos = wcsstr(pos + 1, find))\n+\t\tres = pos;\n+\treturn res;\n+}\n+\n+static int match_part_with_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim, int last)\n {\n \tLPCWSTR delim_pos, start = *ptarget;\n \tint len;\n \n \t/* find start of delimiter (or end-of-string if delim is empty) */\n \tif (*delim)\n-\t\tdelim_pos = wcsstr(start, delim);\n+\t\tdelim_pos = last ? wcsstr_last(start, delim) : wcsstr(start, delim);\n \telse\n \t\tdelim_pos = start + wcslen(start);\n \n@@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n \treturn !want || (!wcsncmp(want, start, len) && !want[len]);\n }\n \n+static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+{\n+\treturn match_part_with_last(ptarget, want, delim, 0);\n+}\n+\n+static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+{\n+\treturn match_part_with_last(ptarget, want, delim, 1);\n+}\n+\n static int match_cred(const CREDENTIALW *cred)\n {\n \tLPCWSTR target = cred->TargetName;\n@@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)\n \n \treturn match_part(&target, L\"git\", L\":\") &&\n \t\tmatch_part(&target, protocol, L\"://\") &&\n-\t\tmatch_part(&target, wusername, L\"@\") &&\n+\t\tmatch_part_last(&target, wusername, L\"@\") &&\n \t\tmatch_part(&target, host, L\"/\") &&\n \t\tmatch_part(&target, path, L\"\");\n }\n-- \n1.9.4.msysgit.2\n"},{"id":"252218","messageId":"1416433652-6840-1-git-send-email-margtu-fivt@ya.ru","threadId":"37946","inReplyTo":"1415832746-5116-1-git-send-email-margtu-fivt@ya.ru","subject":"[PATCH] wincred: fix get credential if username has @","fromName":"Aleksey Vasenev","fromEmail":"margtu-fivt@ya.ru","sentAt":"2014-11-19T21:47:32Z","receivedAt":"2014-11-19T21:47:32Z","isPatch":true,"sender":{"key":"margtu-fivt@ya.ru","avatar":"https://avatars.githubusercontent.com/u/2958497?v=4"},"body":"Signed-off-by: Aleksey Vasenev <margtu-fivt@ya.ru>\n---\n .../credential/wincred/git-credential-wincred.c    | 25 +++++++++++++++++++---\n 1 file changed, 22 insertions(+), 3 deletions(-)\n\ndiff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\nindex a1d38f0..0061340 100644\n--- a/contrib/credential/wincred/git-credential-wincred.c\n+++ b/contrib/credential/wincred/git-credential-wincred.c\n@@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n  * Match an (optional) expected string and a delimiter in the target string,\n  * consuming the matched text by updating the target pointer.\n  */\n-static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+\n+static LPCWSTR wcsstr_last(LPCWSTR str, LPCWSTR find)\n+{\n+\tLPCWSTR res = NULL, pos;\n+\tfor (pos = wcsstr(str, find); pos; pos = wcsstr(pos + 1, find))\n+\t\tres = pos;\n+\treturn res;\n+}\n+\n+static int match_part_with_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim, int last)\n {\n \tLPCWSTR delim_pos, start = *ptarget;\n \tint len;\n \n \t/* find start of delimiter (or end-of-string if delim is empty) */\n \tif (*delim)\n-\t\tdelim_pos = wcsstr(start, delim);\n+\t\tdelim_pos = last ? wcsstr_last(start, delim) : wcsstr(start, delim);\n \telse\n \t\tdelim_pos = start + wcslen(start);\n \n@@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n \treturn !want || (!wcsncmp(want, start, len) && !want[len]);\n }\n \n+static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+{\n+\treturn match_part_with_last(ptarget, want, delim, 0);\n+}\n+\n+static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n+{\n+\treturn match_part_with_last(ptarget, want, delim, 1);\n+}\n+\n static int match_cred(const CREDENTIALW *cred)\n {\n \tLPCWSTR target = cred->TargetName;\n@@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)\n \n \treturn match_part(&target, L\"git\", L\":\") &&\n \t\tmatch_part(&target, protocol, L\"://\") &&\n-\t\tmatch_part(&target, wusername, L\"@\") &&\n+\t\tmatch_part_last(&target, wusername, L\"@\") &&\n \t\tmatch_part(&target, host, L\"/\") &&\n \t\tmatch_part(&target, path, L\"\");\n }\n-- \n1.9.4.msysgit.2\n"},{"id":"252223","messageId":"xmqq1toyreyh.fsf@gitster.dls.corp.google.com","threadId":"37946","inReplyTo":"1416433652-6840-1-git-send-email-margtu-fivt@ya.ru","subject":"Re: [PATCH] wincred: fix get credential if username has @","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-19T22:41:10Z","receivedAt":"2014-11-19T22:41:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Aleksey Vasenev <margtu-fivt@ya.ru> writes:\n\n>> To: git@vger.kernel.org\n>> Cc: Junio C Hamano <gitster@pobox.com>, Aleksey Vasenev <margtu-fivt@ya.ru>\n\nSorry, but I am hardly qualified to review this one, especially\nwithout any log message that explains what breaks and how it breaks\nwith the current code, which may lead the reader to understand how\nthe updated code fixes the issue.  Cc'ing me does not help us very\nmuch.\n\n    $ git shortlog --no-merges -n contrib/credential/wincred/\n\ngives me a few names who may be able to give us some inputs, so I'll\nCc them.\n\nThanks.\n\n> Signed-off-by: Aleksey Vasenev <margtu-fivt@ya.ru>\n> ---\n>  .../credential/wincred/git-credential-wincred.c    | 25 +++++++++++++++++++---\n>  1 file changed, 22 insertions(+), 3 deletions(-)\n>\n> diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\n> index a1d38f0..0061340 100644\n> --- a/contrib/credential/wincred/git-credential-wincred.c\n> +++ b/contrib/credential/wincred/git-credential-wincred.c\n> @@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n>   * Match an (optional) expected string and a delimiter in the target string,\n>   * consuming the matched text by updating the target pointer.\n>   */\n> -static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n> +\n> +static LPCWSTR wcsstr_last(LPCWSTR str, LPCWSTR find)\n> +{\n> +\tLPCWSTR res = NULL, pos;\n> +\tfor (pos = wcsstr(str, find); pos; pos = wcsstr(pos + 1, find))\n> +\t\tres = pos;\n> +\treturn res;\n> +}\n> +\n> +static int match_part_with_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim, int last)\n>  {\n>  \tLPCWSTR delim_pos, start = *ptarget;\n>  \tint len;\n>  \n>  \t/* find start of delimiter (or end-of-string if delim is empty) */\n>  \tif (*delim)\n> -\t\tdelim_pos = wcsstr(start, delim);\n> +\t\tdelim_pos = last ? wcsstr_last(start, delim) : wcsstr(start, delim);\n>  \telse\n>  \t\tdelim_pos = start + wcslen(start);\n>  \n> @@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n>  \treturn !want || (!wcsncmp(want, start, len) && !want[len]);\n>  }\n>  \n> +static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n> +{\n> +\treturn match_part_with_last(ptarget, want, delim, 0);\n> +}\n> +\n> +static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n> +{\n> +\treturn match_part_with_last(ptarget, want, delim, 1);\n> +}\n> +\n>  static int match_cred(const CREDENTIALW *cred)\n>  {\n>  \tLPCWSTR target = cred->TargetName;\n> @@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)\n>  \n>  \treturn match_part(&target, L\"git\", L\":\") &&\n>  \t\tmatch_part(&target, protocol, L\"://\") &&\n> -\t\tmatch_part(&target, wusername, L\"@\") &&\n> +\t\tmatch_part_last(&target, wusername, L\"@\") &&\n>  \t\tmatch_part(&target, host, L\"/\") &&\n>  \t\tmatch_part(&target, path, L\"\");\n>  }\n"},{"id":"255280","messageId":"CABPQNSaNHU=eJtK=s4P=p0hesEB0fxnwRo1zx5sMDo7zXgYM_A@mail.gmail.com","threadId":"37946","inReplyTo":"xmqq1toyreyh.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH] wincred: fix get credential if username has @","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2015-01-25T21:12:15Z","receivedAt":"2015-01-25T21:12:15Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Sorry for the extremely delayed reply, I had a bug in my mail-filters.\nHopefully fixed now.\n\nOn Wed, Nov 19, 2014 at 11:41 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Aleksey Vasenev <margtu-fivt@ya.ru> writes:\n>\n>>> To: git@vger.kernel.org\n>>> Cc: Junio C Hamano <gitster@pobox.com>, Aleksey Vasenev <margtu-fivt@ya.ru>\n>\n> Sorry, but I am hardly qualified to review this one, especially\n> without any log message that explains what breaks and how it breaks\n> with the current code, which may lead the reader to understand how\n> the updated code fixes the issue.  Cc'ing me does not help us very\n> much.\n>\n>     $ git shortlog --no-merges -n contrib/credential/wincred/\n>\n> gives me a few names who may be able to give us some inputs, so I'll\n> Cc them.\n>\n> Thanks.\n\nI noticed the breakage myself around the same time, and posted about it here:\n\nhttps://groups.google.com/d/msg/msysgit/YVuCqmwwRyY/HULHj5OoE88J\n\nUnfortunately, it stopped there.\n\n>> Signed-off-by: Aleksey Vasenev <margtu-fivt@ya.ru>\n>> ---\n>>  .../credential/wincred/git-credential-wincred.c    | 25 +++++++++++++++++++---\n>>  1 file changed, 22 insertions(+), 3 deletions(-)\n>>\n>> diff --git a/contrib/credential/wincred/git-credential-wincred.c b/contrib/credential/wincred/git-credential-wincred.c\n>> index a1d38f0..0061340 100644\n>> --- a/contrib/credential/wincred/git-credential-wincred.c\n>> +++ b/contrib/credential/wincred/git-credential-wincred.c\n>> @@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)\n>>   * Match an (optional) expected string and a delimiter in the target string,\n>>   * consuming the matched text by updating the target pointer.\n>>   */\n>> -static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n>> +\n>> +static LPCWSTR wcsstr_last(LPCWSTR str, LPCWSTR find)\n>> +{\n>> +     LPCWSTR res = NULL, pos;\n>> +     for (pos = wcsstr(str, find); pos; pos = wcsstr(pos + 1, find))\n>> +             res = pos;\n>> +     return res;\n>> +}\n>> +\n\nUgh, there's no wcsrstr? I guess this is a reasonable way to emulate it...\n\n>> +static int match_part_with_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim, int last)\n>>  {\n>>       LPCWSTR delim_pos, start = *ptarget;\n>>       int len;\n>>\n>>       /* find start of delimiter (or end-of-string if delim is empty) */\n>>       if (*delim)\n>> -             delim_pos = wcsstr(start, delim);\n>> +             delim_pos = last ? wcsstr_last(start, delim) : wcsstr(start, delim);\n>>       else\n>>               delim_pos = start + wcslen(start);\n>>\n>> @@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n>>       return !want || (!wcsncmp(want, start, len) && !want[len]);\n>>  }\n>>\n>> +static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n>> +{\n>> +     return match_part_with_last(ptarget, want, delim, 0);\n>> +}\n>> +\n>> +static int match_part_last(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)\n>> +{\n>> +     return match_part_with_last(ptarget, want, delim, 1);\n>> +}\n>> +\n>>  static int match_cred(const CREDENTIALW *cred)\n>>  {\n>>       LPCWSTR target = cred->TargetName;\n>> @@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)\n>>\n>>       return match_part(&target, L\"git\", L\":\") &&\n>>               match_part(&target, protocol, L\"://\") &&\n>> -             match_part(&target, wusername, L\"@\") &&\n>> +             match_part_last(&target, wusername, L\"@\") &&\n>>               match_part(&target, host, L\"/\") &&\n>>               match_part(&target, path, L\"\");\n>>  }\n\nLooks reasonable enough to me.\n\nAcked-by: Erik Faye-Lund <kusmabite@gmail.com>\n"},{"id":"255284","messageId":"xmqqy4oqmalq.fsf@gitster.dls.corp.google.com","threadId":"37946","inReplyTo":"CABPQNSaNHU=eJtK=s4P=p0hesEB0fxnwRo1zx5sMDo7zXgYM_A@mail.gmail.com","subject":"Re: [PATCH] wincred: fix get credential if username has @","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-26T04:25:53Z","receivedAt":"2015-01-26T04:25:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Erik Faye-Lund <kusmabite@gmail.com> writes:\n\n> Sorry for the extremely delayed reply, I had a bug in my mail-filters.\n> Hopefully fixed now.\n>\n> ...\n>\n> I noticed the breakage myself around the same time, and posted about it here:\n>\n> https://groups.google.com/d/msg/msysgit/YVuCqmwwRyY/HULHj5OoE88J\n>\n> Unfortunately, it stopped there.\n> ...\n>\n> Looks reasonable enough to me.\n>\n> Acked-by: Erik Faye-Lund <kusmabite@gmail.com>\n\nOK.  Will apply to my tree, so future Git for Windows would\nhopefully have it as part of its upstream updates.\n\nThanks.\n"}]}