git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: git@vger.kernel.org, Jan Viktorin <viktorin@rehivetech.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] send-email: fix uninitialized var warning for $smtp_auth
Date: Fri, 18 Sep 2015 18:25:24 -0400	[thread overview]
Message-ID: <20150918222524.GA22410@flurp.local> (raw)
In-Reply-To: <1442614370-39880-1-git-send-email-computersforpeace@gmail.com>

On Fri, Sep 18, 2015 at 03:12:50PM -0700, Brian Norris wrote:
> 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.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> ---
>  git-send-email.perl | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/git-send-email.perl b/git-send-email.perl
> index c5a3f766f7fd..e3ff44b4d0cd 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -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< ---
diff --git a/git-send-email.perl b/git-send-email.perl
index c5a3f76..2a5ceda 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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< ---

  reply	other threads:[~2015-09-18 22:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18 22:12 [PATCH] send-email: fix uninitialized var warning for $smtp_auth Brian Norris
2015-09-18 22:25 ` Eric Sunshine [this message]
2015-09-18 22:42   ` Brian Norris
2015-09-18 22:47     ` Eric Sunshine
2015-09-18 22:50       ` Brian Norris
2015-09-21 17:52 ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150918222524.GA22410@flurp.local \
    --to=sunshine@sunshineco.com \
    --cc=computersforpeace@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=viktorin@rehivetech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).