user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] Import: Be more careful with names in email
@ 2020-07-03 21:53 Eric W. Biederman
  2020-07-03 23:30 ` Eric Wong
  0 siblings, 1 reply; 6+ messages in thread
From: Eric W. Biederman @ 2020-07-03 21:53 UTC (permalink / raw)
  To: Eric Wong; +Cc: meta


I recent encountered a nasty (in several sense of the word) from line:

From: =?UTF-8?B?DQolLg0KSVwnbSBhIGhvcm55IGJyYXppbGlhbiBhbmQgSVwnbSBuZXcgaGVyZS4gSVwnbSBzZWFyY2hpbmcgZm9yIGEgZ3V5IHRvIGZ1Y2sgbWUgZnJvbSBiZWhpbmQgdGhpcyBldmVuaW5nLiBUZXh0IG1lIHNvb24gaHR0cDovL2NlbnRwZWFkb3RvdGFiLmNmL3JBbmdpZQ0KDQogJHB4Mm9ybTVuam1lDQoNCg0KDQoNCg0KDQoNCg0KDQoNCg0KDQoNCg0=?= <wordpress@practicalhomeschooler.com>

After extract_cmt_info was extracted and decoded the ``name'',
passing that decoded ``name'' to git fast-import caused it
to choke.  Something about a missing '>'.

To prevent this happening in the future transform a few more characters
into spaces, and don't use string interpolation, use comma separated
variables instead.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
---

I honestly don't know if I have closed all of the holes
when implementing the code this way.  But this changes works for me(tm).
Feel free to treat this as a bug report instead of a patch to apply.

 lib/PublicInbox/Import.pm | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Import.pm b/lib/PublicInbox/Import.pm
index 66b359023bd2..df6c78368845 100644
--- a/lib/PublicInbox/Import.pm
+++ b/lib/PublicInbox/Import.pm
@@ -310,7 +310,7 @@ sub extract_cmt_info ($;$) {
 	# ref:
 	# <CAD0k6qSUYANxbjjbE4jTW4EeVwOYgBD=bXkSu=akiYC_CB7Ffw@mail.gmail.com>
 	if (defined $name) {
-		$name =~ tr/<>//d;
+		$name =~ tr/\n\r<>$/     /d;
 		utf8::encode($name);
 	} else {
 		$name = '';
@@ -425,9 +425,10 @@ sub add {
 		print $w "reset $ref\n" or wfail;
 	}
 
-	print $w "commit $ref\nmark :$commit\n",
-		"author $name <$email> $at\n",
-		"committer $self->{ident} $ct\n" or wfail;
+	# Be very careful with the strings from the email
+	print $w "commit ", $ref, "\nmark :", $commit, "\n",
+		"author ", $name, " <", $email, "> ", $at, "\n",
+		"committer ", $self->{ident}, " ", $ct, "\n" or wfail;
 	print $w "data ", (length($subject) + 1), "\n",
 		$subject, "\n\n" or wfail;
 	if ($tip ne '') {
-- 
2.20.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-07-05 14:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-03 21:53 [PATCH] Import: Be more careful with names in email Eric W. Biederman
2020-07-03 23:30 ` Eric Wong
2020-07-04 20:25   ` [PATCH] t/import: test for nasty characters Eric Wong
2020-07-04 20:28     ` Eric W. Biederman
2020-07-04 21:24       ` Eric Wong
2020-07-05 14:55       ` Leah Neukirchen

Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.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).