git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] symbolic-ref: check format of given reference
@ 2012-06-17 20:26 Michael Schubert
  2012-06-17 20:55 ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Schubert @ 2012-06-17 20:26 UTC (permalink / raw)
  To: git

Currently, it's possible to update HEAD with a nonsense reference since
no strict validation is performed. Example:

	$ git symbolic-ref HEAD 'refs/heads/master
    >
    >
    > '

Fix this by checking the given reference with check_refname_format().

Signed-off-by: Michael Schubert <mschub@elegosoft.com>
---

This was discussed earlier this year:

http://thread.gmane.org/gmane.comp.version-control.git/189715

What about pointing at non-existing references? Should this
still be allowed?

Additionally, I had to reindent two lines to make git-am happy
(indent with spaces).

 builtin/symbolic-ref.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index 801d62e..22362e0 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -43,16 +43,18 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
 
 	git_config(git_default_config, NULL);
 	argc = parse_options(argc, argv, prefix, options,
-			     git_symbolic_ref_usage, 0);
-	if (msg &&!*msg)
+				git_symbolic_ref_usage, 0);
+	if (msg && !*msg)
 		die("Refusing to perform update with empty message");
 	switch (argc) {
 	case 1:
 		check_symref(argv[0], quiet);
 		break;
 	case 2:
+		if (check_refname_format(argv[1], 0))
+			die("No valid reference format: '%s'", argv[1]);
 		if (!strcmp(argv[0], "HEAD") &&
-		    prefixcmp(argv[1], "refs/"))
+			prefixcmp(argv[1], "refs/"))
 			die("Refusing to point HEAD outside of refs/");
 		create_symref(argv[0], argv[1], msg);
 		break;
-- 
1.7.11.rc3.11.g7dba3f7.dirty

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

end of thread, other threads:[~2012-06-19 14:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-17 20:26 [PATCH] symbolic-ref: check format of given reference Michael Schubert
2012-06-17 20:55 ` Junio C Hamano
2012-06-18 12:02   ` Michael Schubert
2012-06-18 16:39     ` Junio C Hamano
2012-06-18 17:10       ` Junio C Hamano
2012-06-19 14:47         ` Jeff King
2012-06-19 14:52           ` Jeff King
2012-06-19 14:56       ` Michael Schubert

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).