git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] imap-send: escape backslash in password

From
Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>
Date
Aug 4, 2017, 19:32 UTC
Message-ID
<90b60e41-f59f-a141-1c83-3605444333b4@morey-chaisemartin.com>
In-Reply-To
<xmqqbmnvtain.fsf@gitster.mtv.corp.google.com>
Le 04/08/2017 à 21:09, Junio C Hamano a écrit :
> Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> writes:
>
>> Password containing backslashes need to have them doubled to have them properly interpreted by the imap server.
> Please wrap this into lines with reasonable lengths like 72 cols.

I haven't checked the coding style yet. This was a very quick try that I submitted to get some feedback on the approach. WIll fix for next time though.

Show 12 quoted lines
>
> Is the quoting rules documented somewhere?  If so, please also give
> a reference to it here.  RFC3501 "6.2.3 LOGIN Command" does not say
> much (other parts of the RFC may specify the rules that apply to
> arguments in general, but I didn't look for them).  Without such
> reference, it is hard to judge if this change is sufficient or even
> correct (in an extreme case, the IMAP server you are talking with
> that prompted you to make this change might be in violation).
>
> For example, FRC3501 "9. Formal Syntax" says that both "password"
> and "userid" are "astring"; it looks strange that the code with this
> patch only touches cred.password while sending cred.username as-is.

Didn't found a RFC doc on this. I hit the bug today and looking at the error message, found a few people who add the issue with different client and required escaping backslashes It probably applies to the username (would be logicial that both string in the line are parsed the same way) not sure if backslashes are allowed in username though. With password generator, they are more likely to be there. But it wouldn't hurt to use the escape function for both.

>> +static char* imap_escape_password(const char *passwd)
> In our codebase, asterisk sticks to identifier, not typename.  I.e.
>
> 	static char *imap_escape(...)

Will do. BTW, is there a checkpatch or similar for git ? Scrolled quickly through the doc and did not see any reference.

Show 36 quoted lines
>
>> +{
>> +	const unsigned passwd_len = strlen(passwd);
>> +	char *escaped = xmalloc(2 * passwd_len + 1);
>> +	const char *passwd_cur = passwd;
>> +	char *escaped_cur = escaped;
>> +
>> +	do {
>> +		char *next = strchr(passwd_cur, '\\');
>> +
>> +		if (!next) {
>> +			strcpy(escaped_cur, passwd_cur);
>> +		} else {
>> +			int len = next - passwd_cur + 1;
>> +
>> +			memcpy(escaped_cur, passwd_cur, len);
>> +			escaped_cur += len;
>> +			next++;
>> +			*(escaped_cur++) = '\\';
>> +		}
>> +		passwd_cur = next;
>> +	} while(passwd_cur);
>> +
>> +	return escaped;
>> +}
> I wonder if we should use strbuf here perhaps like so:
>
> 	struct strbuf encoded = STRBUF_INIT;
> 	const char *p;
>
> 	for (p = passwd; *p; p++) {
> 		if (need_bs_quote(*p))
> 			strbuf_addch(&encoded, '\\');
> 		strbuf_addch(&encoded, *p);
> 	}
> 	return strbuf_detach(&encoded, NULL);

I looked at the wrappers and wasn't sure if they were to be used for this (one of the main reason this is an RFC). I guess it would make sense. I'm not familiar with git code, but is there other escape function of this kind that could be factor ? Or the function is simple enough not to be worth it ?

Thanks
Nicolas
Previous: Junio C HamanoNext: Andreas Schwab
Message 3 of 15 in “[RFC] imap-send: escape backslash in password”
  1. Nicolas Morey-ChaisemartinAug 4, 2017
  2. Junio C HamanoAug 4, 2017
  3. Nicolas Morey-ChaisemartinAug 4, 2017
  4. Andreas SchwabAug 4, 2017
  5. Jeff KingAug 4, 2017
  6. Junio C HamanoAug 4, 2017
  7. Jeff KingAug 4, 2017
  8. Nicolas Morey-ChaisemartinAug 6, 2017
  9. Jeff KingAug 7, 2017
  10. Junio C HamanoAug 7, 2017
  11. Jeff KingAug 8, 2017
  12. Junio C HamanoAug 8, 2017
  13. Jeff KingAug 9, 2017
  14. brian m. carlsonAug 4, 2017
  15. Jeff KingAug 4, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.