Re: [PATCH 1/2] git-svn, perl/Git.pm: add central method for prompting passwords honoring GIT_ASKPASS and SSH_ASKPASS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 04.01.2012 01:10 schrieb Junio C Hamano:
> I'll queue both of them in 'pu' for now just in case others spot silly
> mistakes I made while rewriting the first one, though.

I just hit another issue (I created another patch, but we might want to
integrate it into the first one). This is especially needed if we want
to apply my second patch in this mail.
From: Sven Strickroth <email@xxxxxxxxxx>
Date: Wed, 4 Jan 2012 08:32:13 +0100
Subject: [PATCH] Git.pm: check if value is defined before accessing it

Some perl versions, like the one from msys, crash sometimes
if reading from STDIN wasn't successful and chomp is applied
to the variable into which was read.

Errormessage:
Username: Use of uninitialized value in chomp at C:\Program
Files\Git/libexec/git-core\git-svn line 4321.
0 [main] perl.exe" 1916 handle_exceptions: Exception:
STATUS_ACCESS_VIOLATION
1297 [main] perl.exe" 1916 open_stackdumpfile: Dumping stack trace to
perl.exe.stackdump

Signed-off-by: Sven Strickroth <email@xxxxxxxxxx>
---
 perl/Git.pm |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 33e68c4..1c96a20 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -547,7 +547,12 @@ sub prompt {
 			print STDERR "\n";
 			STDERR->flush;
 		} else {
-			chomp($ret = <STDIN>);
+			$ret = <STDIN>;
+			if (defined $ret) {
+				chomp($ret);
+			} else {
+				$ret = '';
+			}
 		}
 	}
 	return $ret;

> For the second patch, I have a feeling that Peff's earlier suggestion to
> give precedence to the terminal interaction over SSH_ASKPASS iff we can
> open terminal, but I think the first one is OK for 1.7.9.

We also do the wrong order for querying the password. if we want to
adopt this, we should also update prompt.c, the make both prompt methods
behave the same way again.

The Git.pm part is easy, but I also tried to update prompt.c (untested).
From: Sven Strickroth <email@xxxxxxxxxx>
Date: Wed, 4 Jan 2012 08:44:48 +0100
Subject: [PATCH] Git.pm, prompt: try reading from interactive terminal
before
 using SSH_ASKPASS

SVN tries to read reading from interactive terminal before using
SSH_ASKPASS helper. This change adjust git to behave the same way.

Signed-off-by: Sven Strickroth <email@xxxxxxxxxx>
---
 perl/Git.pm |    6 +++---
 prompt.c    |   14 +++++++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/perl/Git.pm b/perl/Git.pm
index 1c96a20..6ce193e 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -530,9 +530,6 @@ sub prompt {
 		$ret = _prompt($ENV{'GIT_ASKPASS'}, $prompt);
 	}
 	if (!defined $ret) {
-		$ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt);
-	}
-	if (!defined $ret) {
 		print STDERR $prompt;
 		STDERR->flush;
 		if ($isPassword) {
@@ -555,5 +552,8 @@ sub prompt {
 		}
 	}
+	if (!defined $ret) {
+		$ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt);
+	}
 	return $ret;
 }


diff --git a/prompt.c b/prompt.c
index 72ab9de..e791619 100644
--- a/prompt.c
+++ b/prompt.c
@@ -52,9 +52,17 @@ char *git_prompt(const char *prompt, int flags)
 	}

 	r = git_terminal_prompt(prompt, flags & PROMPT_ECHO);
-	if (!r)
-		die_errno("could not read '%s'", prompt);
-	return r;
+	if (r)
+		return r;
+
+	if (flags & PROMPT_ASKPASS) {
+		const char *askpass;
+		askpass = getenv("SSH_ASKPASS");
+		if (askpass && *askpass)
+			return do_askpass(askpass, prompt);
+	}
+
+	die_errno("could not read '%s'", prompt);
 }

 char *git_getpass(const char *prompt)
-- 
Best regards,
 Sven Strickroth
 ClamAV, a GPL anti-virus toolkit   http://www.clamav.net
 PGP key id F5A9D4C4 @ any key-server
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]