Commit d164438156e369fe982c409f32bc5568578de040

Stefan Sperling 2019-07-14T14:05:17

prevent 'got ref' from creating references called '-'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/got/got.c b/got/got.c
index 1da3e4d..f1cf050 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2072,6 +2072,14 @@ add_ref(struct got_repository *repo, const char *refname, const char *target)
 	struct got_object_id *id;
 	struct got_reference *ref = NULL;
 
+	/*
+	 * Don't let the user create a reference named '-'.
+	 * While technically a valid reference name, this case is usually
+	 * an unintended typo.
+	 */
+	if (refname[0] == '-' && refname[1] == '\0')
+		return got_error(GOT_ERR_BAD_REF_NAME);
+
 	err = got_repo_match_object_id_prefix(&id, target, GOT_OBJ_TYPE_ANY,
 	    repo);
 	if (err) {