git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Taylor Blau <me@ttaylorr.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>,
	Bagas Sanjaya <bagasdotme@gmail.com>
Subject: [PATCH] git-send-email.perl: avoid printing undef when validating addresses
Date: Mon, 18 Sep 2023 12:35:53 -0400	[thread overview]
Message-ID: <545729b619308c6f3397b9aa1747f26ddc58f461.1695054945.git.me@ttaylorr.com> (raw)
In-Reply-To: <ZQhI5fMhDE82awpE@debian.me>

When validating email addresses with `extract_valid_address_or_die()`,
we print out a helpful error message when the given input does not
contain a valid email address.

However, the pre-image of this patch looks something like:

    my $address = shift;
    $address = extract_valid_address($address):
    die sprintf(__("..."), $address) if !$address;

which fails when given a bogus email address by trying to use $address
(which is undef) in a sprintf() expansion, like so:

    $ git.compile send-email --to="pi <pi@pi>" /tmp/x/*.patch --force
    Use of uninitialized value $address in sprintf at /home/ttaylorr/src/git/git-send-email line 1175.
    error: unable to extract a valid address from:

This regression dates back to e431225569 (git-send-email: remove invalid
addresses earlier, 2012-11-22), but became more noticeable in a8022c5f7b
(send-email: expose header information to git-send-email's
sendemail-validate hook, 2023-04-19), which validates SMTP headers in
the sendemail-validate hook.

Avoid trying to format an undef by storing the given and cleaned address
separately. After applying this fix, the error contains the invalid
email address, and the warning disappears:

    $ git.compile send-email --to="pi <pi@pi>" /tmp/x/*.patch --force
    error: unable to extract a valid address from: pi <pi@pi>

Reported-by: Bagas Sanjaya <bagasdotme@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 git-send-email.perl | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 897cea6564..288ea1ae80 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1166,10 +1166,10 @@ sub extract_valid_address {
 
 sub extract_valid_address_or_die {
 	my $address = shift;
-	$address = extract_valid_address($address);
+	my $valid_address = extract_valid_address($address);
 	die sprintf(__("error: unable to extract a valid address from: %s\n"), $address)
-		if !$address;
-	return $address;
+		if !$valid_address;
+	return $valid_address;
 }
 
 sub validate_address {
-- 
2.42.0.217.g5402a90ddb

  reply	other threads:[~2023-09-18 16:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 12:56 [REGRESSION] uninitialized value $address in git send-email Bagas Sanjaya
2023-09-18 16:35 ` Taylor Blau [this message]
2023-09-18 19:04   ` [PATCH] git-send-email.perl: avoid printing undef when validating addresses Junio C Hamano
2023-09-18 21:20   ` Jeff King
2023-09-18 20:26 ` [REGRESSION] uninitialized value $address in git send-email Michael Strawbridge
2023-09-19  4:44   ` Bagas Sanjaya
2023-09-19 14:04     ` Michael Strawbridge
2023-09-19 14:37       ` Michael Strawbridge
2023-09-20 11:00         ` Bagas Sanjaya
2023-09-20 13:14           ` Michael Strawbridge
2023-09-20 15:43           ` Junio C Hamano
2023-09-21  7:51             ` Bagas Sanjaya
2023-09-21 20:42               ` Junio C Hamano
2023-09-22  7:39                 ` Bagas Sanjaya
2023-09-20 15:36         ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=545729b619308c6f3397b9aa1747f26ddc58f461.1695054945.git.me@ttaylorr.com \
    --to=me@ttaylorr.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).