git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Michael Strawbridge <michael.strawbridge@amd.com>
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Bagas Sanjaya" <bagasdotme@gmail.com>,
	"Todd Zullinger" <tmz@pobox.com>,
	"Luben Tuikov" <luben.tuikov@amd.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Taylor Blau" <me@ttaylorr.com>,
	"Git Mailing List" <git@vger.kernel.org>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Subject: Re: [PATCH] send-email: move process_address_list earlier to avoid, uninitialized address error
Date: Fri, 20 Oct 2023 03:14:02 -0400	[thread overview]
Message-ID: <20231020071402.GC1642714@coredump.intra.peff.net> (raw)
In-Reply-To: <20231020064525.GB1642714@coredump.intra.peff.net>

On Fri, Oct 20, 2023 at 02:45:25AM -0400, Jeff King wrote:

> > I have been looking into handling the interactive input cases while
> > solving this issue, but have yet to make a breakthrough.  Simply
> > moving the validation code below the original process_address_list
> > code results in a a scenario where I get the email address being seen
> > as something like "ARRAY (0x55ddb951d768)" rather than the email
> > address I wrote in the compose buffer.
> 
> Sounds like something is making a perl ref that shouldn't (or something
> that should be dereferencing it not doing so). If you post your patch
> and a reproduction command, I might be able to help debug.

Ah, your "address I wrote in the compose buffer" was the clue I needed.

I think this is actually an existing bug. If I use --compose and write:

  To: foo@example.com

in the editor, we read that back in and handle it in parse_header_line()
like:

        my $addr_pat = join "|", qw(To Cc Bcc);

        foreach (split(/\n/, $lines)) {
                if (/^($addr_pat):\s*(.+)$/i) {
                        $parsed_line->{$1} = [ parse_address_line($2) ];
                } elsif (/^([^:]*):\s*(.+)\s*$/i) {
                        $parsed_line->{$1} = $2;
                }
        }

and there's your perl array ref (from the square brackets, which are
necessary because we're sticking it in a hash value). But even before
your patch, this seems to end up as garbage. The code which reads
$parsed_line does not dereference the array.

The patch to fix it is only a few lines (well, more than that with some
light editorializing in the comments):

diff --git a/git-send-email.perl b/git-send-email.perl
index 76589c7827..46a30088c9 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -918,7 +918,28 @@ sub get_patch_subject {
 	# Preserve unknown headers
 	foreach my $key (keys %parsed_email) {
 		next if $key eq 'body';
-		print $c2 "$key: $parsed_email{$key}";
+
+		# it seems like it would be easier to just look for
+		# $parsed_email{'To'} and so on. But we actually match
+		# these case-insenstively and preserve the user's spelling, so
+		# we might see $parsed_email{'to'}. Of course, the same bug
+		# exists for Subject, etc, above. Anyway, a "/i" regex here
+		# handles all cases.
+		#
+		# It kind of feels like all of this code would be much simpler
+		# if we just handled all of the headers while reading back the
+		# input, rather than stuffing them all into $parsed_email and
+		# then picking them out of it.
+		#
+		# It also really feels like these to/cc/bcc lines should be
+		# added to the regular ones? It is silly to make a cover letter
+		# that goes to some addresses, and then not send the patches to
+		# them, too.
+		if ($key =~ /^(To|Cc|Bcc)$/i) {
+			print $c2 "$key: ", join(', ', @{$parsed_email{$key}});
+		} else {
+			print $c2 "$key: $parsed_email{$key}";
+		}
 	}
 
 	if ($parsed_email{'body'}) {

I don't really think your patch makes things worse here. But it is
probably worth fixing it while we are here.

-Peff

  reply	other threads:[~2023-10-20  7:14 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22  9:27 [REGRESSION] uninitialized value $address in git send-email when given multiple recipients separated by commas Bagas Sanjaya
2023-09-24  3:36 ` Jeff King
2023-09-25  7:45   ` Bagas Sanjaya
2023-09-25  8:00     ` Jeff King
2023-09-25 14:48       ` Todd Zullinger
2023-09-25 16:17         ` Jeff King
2023-10-11 13:41           ` Bagas Sanjaya
2023-10-11 19:27             ` Michael Strawbridge
2023-10-11 20:22               ` [PATCH] send-email: move process_address_list earlier to avoid, uninitialized address error Michael Strawbridge
2023-10-11 20:25                 ` Michael Strawbridge
2023-10-11 21:27                 ` Junio C Hamano
2023-10-11 22:18                   ` Jeff King
2023-10-11 22:37                     ` Junio C Hamano
2023-10-11 22:47                       ` Jeff King
2023-10-13 20:25                         ` Michael Strawbridge
2023-10-20  6:45                           ` Jeff King
2023-10-20  7:14                             ` Jeff King [this message]
2023-10-20 10:03                               ` [PATCH 0/3] some send-email --compose fixes Jeff King
2023-10-20 10:09                                 ` [PATCH 1/3] doc/send-email: mention handling of "reply-to" with --compose Jeff King
2023-10-20 10:13                                 ` [PATCH 2/3] Revert "send-email: extract email-parsing code into a subroutine" Jeff King
2023-10-20 10:45                                   ` Oswald Buddenhagen
2023-10-23 18:40                                     ` Jeff King
2023-10-23 19:50                                       ` Oswald Buddenhagen
2023-10-25  6:11                                         ` Jeff King
2023-10-25  9:23                                           ` Oswald Buddenhagen
2023-10-27 22:31                                             ` Junio C Hamano
2023-10-30  9:13                                             ` Jeff King
2023-10-20 21:45                                   ` Junio C Hamano
2023-10-23 18:47                                     ` Jeff King
2023-10-20 10:15                                 ` [PATCH 3/3] send-email: handle to/cc/bcc from --compose message Jeff King
2023-10-20 17:30                                   ` Eric Sunshine
2023-10-20 21:42                                 ` [PATCH 0/3] some send-email --compose fixes Junio C Hamano
2023-10-23 18:51                                   ` Jeff King
2023-10-24 20:12                                     ` Michael Strawbridge
2023-10-24 20:19                                       ` [PATCH] send-email: move validation code below process_address_list Michael Strawbridge
2023-10-24 21:55                                         ` Junio C Hamano
2023-10-24 22:03                                           ` Junio C Hamano
2023-10-25 18:48                                             ` Michael Strawbridge
2023-10-25 18:51                                             ` [PATCH v2] " Michael Strawbridge
2023-10-26 12:44                                               ` Junio C Hamano
2023-10-26 13:11                                                 ` Michael Strawbridge
2023-10-25  6:50                                         ` [PATCH] " Jeff King
2023-10-25 18:47                                           ` Michael Strawbridge
2023-10-25  7:43                                         ` Uwe Kleine-König
2023-10-27 13:04                                           ` Junio C Hamano
2023-10-20  2:50                 ` [PATCH] send-email: move process_address_list earlier to avoid, uninitialized address error Bagas Sanjaya
2023-09-26 11:33       ` [REGRESSION] uninitialized value $address in git send-email when given multiple recipients separated by commas Bagas Sanjaya

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=20231020071402.GC1642714@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=luben.tuikov@amd.com \
    --cc=me@ttaylorr.com \
    --cc=michael.strawbridge@amd.com \
    --cc=tmz@pobox.com \
    --cc=u.kleine-koenig@pengutronix.de \
    /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).