git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v8 05/10] refname_is_safe(): improve docstring

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 10, 2015, 11:42 UTC
Message-ID
<e3b0c07b34f78996c53df88c17d01cd6a494899d.1447154711.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1447154711.git.mhagger@alum.mit.edu>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 refs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c
index 82129f0..f48c58a 100644
--- a/refs.c
+++ b/refs.c
@@ -341,13 +341,17 @@ static struct ref_dir *get_ref_dir(struct ref_entry *entry)
 }
 
 /*
- * Check if a refname is safe.
- * For refs that start with "refs/" we consider it safe as long they do
- * not try to resolve to outside of refs/.
+ * Return true iff refname is minimally safe. "Safe" here means that
+ * deleting a loose reference by this name will not do any damage, for
+ * example by causing a file that is not a reference to be deleted.
+ * This function does not check that the reference name is legal; for
+ * that, use check_refname_format().
  *
- * For all other refs we only consider them safe iff they only contain
- * upper case characters and '_' (like "HEAD" AND "MERGE_HEAD", and not like
- * "config").
+ * We consider a refname that starts with "refs/" to be safe as long
+ * as any ".." components that it might contain do not escape "refs/".
+ * Names that do not start with "refs/" are considered safe iff they
+ * consist entirely of upper case characters and '_' (like "HEAD" and
+ * "MERGE_HEAD" but not "config" or "FOO/BAR").
  */
 static int refname_is_safe(const char *refname)
 {
-- 
2.6.2
Previous: Michael HaggertyNext: Michael Haggerty
Message 6 of 13 in “refs backend pre-vtable”
  1. 00/10 refs backend pre-vtableMichael Haggerty, Nov 10, 2015
  2. 01/10 verify_refname_available(): rename functionMichael Haggerty, Nov 10, 2015
  3. 02/10 verify_refname_available(): new functionMichael Haggerty, Nov 10, 2015
  4. 03/10 copy_msg(): rename to copy_reflog_msg()Michael Haggerty, Nov 10, 2015
  5. 04/10 pack_if_possible_fn(): use ref_type() instead of is_per_worktree_ref()Michael Haggerty, Nov 10, 2015
  6. 05/10 refname_is_safe(): improve docstringMichael Haggerty, Nov 10, 2015
  7. 06/10 refs/refs-internal.h: new header fileMichael Haggerty, Nov 10, 2015
  8. 08/10 initdb: make safe_create_dir publicMichael Haggerty, Nov 10, 2015
  9. 09/10 files_log_ref_write: new functionMichael Haggerty, Nov 10, 2015
  10. 10/10 refs: break out ref conflict checksMichael Haggerty, Nov 10, 2015
  11. David TurnerNov 16, 2015
  12. Jeff KingNov 19, 2015
  13. Michael HaggertyNov 20, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.