Subject: Re: [PATCH v3 2/3] git-core: Support retrieving passwords with GIT_ASKPASS

From: Johannes Sixt <[email-masked]>
Date: Tue, 02 Mar 2010 13:17:22 +0100

Frank Li schrieb:
> +	memset(&pass, 0, sizeof(pass));
> +	pass.argv = args;
> +	pass.out = -1;
> +	pass.use_shell = 1;

I thought that the conclusion was to follow how openssh treats
SSH_ASKPASS, and it *does not* treat it as a command with arguments. Do
not set use_shell.

> +	if (start_command(&pass)) {
> +		error("could not run %s\n", askpass);

As I said, this error message is redundant. No big deal, though.

> +		exit(1);
> +	}
> +
> +	strbuf_read(&buffer, pass.out, 20);
> +	close(pass.out);
> +	finish_command(&pass);

You must check for errors here as well. No error message is needed, either.

> +
> +	for (i = 0; i < buffer.len; i++)
> +		if (buffer.buf[i] == '\n' || buffer.buf[i] == '\r') {
> +			buffer.buf[i] = '\0';
> +			buffer.len = i;
> +		}

I think you can shorten this loop to

	strbuf_setlen(&buffer, strcspn(buffer.buf, "\r\n"));

-- Hannes