git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: bs.x.ttp@recursor.net
Cc: git@vger.kernel.org
Subject: [PATCH 3/4] ident: reject all-crud ident name
Date: Thu, 23 Feb 2017 03:15:55 -0500	[thread overview]
Message-ID: <20170223081555.3yfgm2l7dsjbk4y5@sigill.intra.peff.net> (raw)
In-Reply-To: <20170223081157.hwfn3msfux5udmng@sigill.intra.peff.net>

An ident name consisting of only "crud" characters (like
whitespace or punctuation) is effectively the same as an
empty one, because our strbuf_addstr_without_crud() will
remove those characters.

We reject an empty name when formatting a strict ident, but
don't notice an all-crud one because our check happens
before the crud-removal step.

We could skip past the crud before checking for an empty
name, but let's make it a separate code path, for two
reasons. One is that we can give a more specific error
message. And two is that unlike a blank name, we probably
don't want to kick in the fallback-to-username behavior.

Signed-off-by: Jeff King <peff@peff.net>
---
 ident.c                       | 11 +++++++++++
 t/t7518-ident-corner-cases.sh |  5 +++++
 2 files changed, 16 insertions(+)

diff --git a/ident.c b/ident.c
index ea6034581..ead09ff7f 100644
--- a/ident.c
+++ b/ident.c
@@ -203,6 +203,15 @@ static int crud(unsigned char c)
 		c == '\'';
 }
 
+static int has_non_crud(const char *str)
+{
+	for (; *str; str++) {
+		if (!crud(*str))
+			return 1;
+	}
+	return 0;
+}
+
 /*
  * Copy over a string to the destination, but avoid special
  * characters ('\n', '<' and '>') and remove crud at the end
@@ -389,6 +398,8 @@ const char *fmt_ident(const char *name, const char *email,
 			pw = xgetpwuid_self(NULL);
 			name = pw->pw_name;
 		}
+		if (strict && !has_non_crud(name))
+			die(_("name consists only of disallowed characters: %s"), name);
 	}
 
 	strbuf_reset(&ident);
diff --git a/t/t7518-ident-corner-cases.sh b/t/t7518-ident-corner-cases.sh
index 6c057afc1..3d2560c3c 100755
--- a/t/t7518-ident-corner-cases.sh
+++ b/t/t7518-ident-corner-cases.sh
@@ -17,4 +17,9 @@ test_expect_success 'empty name and missing email' '
 	)
 '
 
+test_expect_success 'commit rejects all-crud name' '
+	test_must_fail env GIT_AUTHOR_NAME=" .;<>" \
+		git commit --allow-empty -m foo
+'
+
 test_done
-- 
2.12.0.rc2.597.g959f68882


  parent reply	other threads:[~2017-02-23  8:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-03  4:13 possible bug: inconsistent CLI behaviour for empty user.name bs.x.ttp
2017-02-23  8:11 ` Jeff King
2017-02-23  8:12   ` [PATCH 1/4] ident: mark error messages for translation Jeff King
2017-02-23  8:13   ` [PATCH 2/4] ident: handle NULL email when complaining of empty name Jeff King
2017-02-23  8:15   ` Jeff King [this message]
2017-02-23  8:17   ` [PATCH 4/4] ident: do not ignore empty config name/email Jeff King
2017-02-23 20:58     ` Junio C Hamano
2017-02-24  1:08       ` Jeff King
2017-02-24  4:11         ` Junio C Hamano
2017-02-24  4:18           ` Jeff King
2017-02-27 15:08             ` Dennis Kaarsemaker
2017-02-27 20:42               ` Junio C Hamano
2017-02-28  5:28                 ` Christian Couder

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=20170223081555.3yfgm2l7dsjbk4y5@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=bs.x.ttp@recursor.net \
    --cc=git@vger.kernel.org \
    /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).