Skip to contentSkip to conversation

send-email: fix uninitialized var warning for $smtp_auth

PATCH In review Brian Norris 3 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 send-email: fix uninitialized var warning for $smtp_auth

On the latest version of git-send-email, I see this error just before running SMTP auth (I didn't provide any --smtp-auth= parameter):

Use of uninitialized value $smtp_auth in pattern match (m//) at /usr/local/google/home/briannorris/git/git/git-send-email.perl line 1139.

Cc Jan Viktorin <[email protected]>
Cc Eric Sunshine <[email protected]>
Cc Junio C Hamano <[email protected]>
---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +1 -1
index c5a3f766f7fd..e3ff44b4d0cd 100755
@@ -1136,7 +1136,7 @@ sub smtp_auth_maybe {
 
 	# Check mechanism naming as defined in:
 	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+	if ($smtp_auth && $smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
 		die "invalid smtp auth: '${smtp_auth}'";
 	}
 
Signature · 1 line
2.6.0.rc0.131.gf624c3d
#1 lore raw
Quoted 15 lines · Brian Norris

On the latest version of git-send-email, I see this error just before running SMTP auth (I didn't provide any --smtp-auth= parameter):

Use of uninitialized value $smtp_auth in pattern match (m//) at /usr/local/google/home/briannorris/git/git/git-send-email.perl line 1139.

---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +0 -0
index c5a3f766f7fd..e3ff44b4d0cd 100755

git-send-email.perl sub smtp_auth_maybe { · line 1141

Quoted 7 lines
git-send-email.perl +1 -1
@@ -1136,7 +1136,7 @@ sub smtp_auth_maybe {
 
 	# Check mechanism naming as defined in:
 	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+	if ($smtp_auth && $smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
 		die "invalid smtp auth: '${smtp_auth}'";
 	}

Thanks, makes sense. I wonder if moving the check to the point where $smtp_auth is actually used (despite the noisier diff) would be cleaner, like this:

--- 8< ---

git-send-email.perl +6 -6
index c5a3f76..2a5ceda 100755
@@ -1134,12 +1134,6 @@ sub smtp_auth_maybe {
 		Authen::SASL->import(qw(Perl));
 	};
 
-	# Check mechanism naming as defined in:
-	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
-		die "invalid smtp auth: '${smtp_auth}'";
-	}
-
 	# TODO: Authentication may fail not because credentials were
 	# invalid but due to other reasons, in which we should not
 	# reject credentials.
@@ -1154,6 +1148,12 @@ sub smtp_auth_maybe {
 		my $cred = shift;
 
 		if ($smtp_auth) {
+			# Check mechanism naming as defined in:
+			# https://tools.ietf.org/html/rfc4422#page-8
+			if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+				die "invalid smtp auth: '${smtp_auth}'";
+			}
+
 			my $sasl = Authen::SASL->new(
 				mechanism => $smtp_auth,
 				callback => {

--- 8< ---

#2 lore raw
Quoted 38 lines · Eric Sunshine

git-send-email.perl sub smtp_auth_maybe { · line 1141

Quoted 10 lines · Brian Norris
git-send-email.perl +1 -1
@@ -1136,7 +1136,7 @@ sub smtp_auth_maybe {
 
 	# Check mechanism naming as defined in:
 	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+	if ($smtp_auth && $smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
 		die "invalid smtp auth: '${smtp_auth}'";
 	}

Thanks, makes sense. I wonder if moving the check to the point where $smtp_auth is actually used (despite the noisier diff) would be cleaner, like this:

--- 8< ---

git-send-email.perl +0 -6
index c5a3f76..2a5ceda 100755
@@ -1134,12 +1134,6 @@ sub smtp_auth_maybe {
 		Authen::SASL->import(qw(Perl));
 	};
 
-	# Check mechanism naming as defined in:
-	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
-		die "invalid smtp auth: '${smtp_auth}'";
-	}
-
 	# TODO: Authentication may fail not because credentials were
 	# invalid but due to other reasons, in which we should not
 	# reject credentials.
@@ -1154,6 +1148,12 @@ sub smtp_auth_maybe {
 		my $cred = shift;
 
 		if ($smtp_auth) {

git-send-email.perl sub smtp_auth_maybe {

Quoted 10 lines
git-send-email.perl +6 -1
+			# Check mechanism naming as defined in:
+			# https://tools.ietf.org/html/rfc4422#page-8
+			if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+				die "invalid smtp auth: '${smtp_auth}'";
+			}
+
 			my $sasl = Authen::SASL->new(
 				mechanism => $smtp_auth,
 				callback => {
--- 8< ---

By moving the patch into the sub-subroutine (is this a lambda? I'm not too familiar with my perl), I think you change the order of the checks. So, previously, initial password auth would happen after the $smtp_auth format check. With your patch, it comes first.

My patch:

  $ git send-email --smtp-auth="@" ...
  ...
  Send this email? ([y]es|[n]o|[q]uit|[a]ll): y
  invalid smtp auth: '@' at ./git-send-email.perl line 1140.

Your patch:

  $ git send-email --smtp-auth="@" ...
  ...
  Send this email? ([y]es|[n]o|[q]uit|[a]ll): y
  Password for xxxx:
  invalid smtp auth: '@' at ./git-send-email.perl line 1155.

Seems like the former is a little better, so you don't have to waste time with your password too many times.

Regards,
Brian

#3 lore raw
Quoted 18 lines · Brian Norris
Quoted 2 lines · Eric Sunshine

Thanks, makes sense. I wonder if moving the check to the point where $smtp_auth is actually used (despite the noisier diff) would be cleaner,

By moving the patch into the sub-subroutine (is this a lambda? I'm not too familiar with my perl), I think you change the order of the checks. So, previously, initial password auth would happen after the $smtp_auth format check. With your patch, it comes first.

My patch:

  $ git send-email --smtp-auth="@" ...
  ...
  Send this email? ([y]es|[n]o|[q]uit|[a]ll): y
  invalid smtp auth: '@' at ./git-send-email.perl line 1140.

Your patch:

Quoted 8 lines
  $ git send-email --smtp-auth="@" ...
  ...
  Send this email? ([y]es|[n]o|[q]uit|[a]ll): y
  Password for xxxx:
  invalid smtp auth: '@' at ./git-send-email.perl line 1155.

Seems like the former is a little better, so you don't have to waste time with your password too many times.

Makes sense (again). Thanks for the explanation.

#4 lore raw
Quoted 1 line · Eric Sunshine

Makes sense (again). Thanks for the explanation.

No problem. Thanks for the review.

#5 lore raw
In reply to Brian Norris
Quoted 18 lines · Brian Norris

On the latest version of git-send-email, I see this error just before running SMTP auth (I didn't provide any --smtp-auth= parameter):

Use of uninitialized value $smtp_auth in pattern match (m//) at /usr/local/google/home/briannorris/git/git/git-send-email.perl line 1139.

Cc Jan Viktorin <[email protected]>
Cc Eric Sunshine <[email protected]>
Cc Junio C Hamano <[email protected]>
---
 git-send-email.perl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
git-send-email.perl +0 -0
index c5a3f766f7fd..e3ff44b4d0cd 100755

git-send-email.perl sub smtp_auth_maybe { · line 1141

Quoted 7 lines
git-send-email.perl +1 -1
@@ -1136,7 +1136,7 @@ sub smtp_auth_maybe {
 
 	# Check mechanism naming as defined in:
 	# https://tools.ietf.org/html/rfc4422#page-8
-	if ($smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
+	if ($smtp_auth && $smtp_auth !~ /^(\b[A-Z0-9-_]{1,20}\s*)*$/) {
 		die "invalid smtp auth: '${smtp_auth}'";
 	}

Thanks.