From aaef0919608668b7a18510fd1d92d494dc14fefc Mon Sep 17 00:00:00 2001 From: Sergei Zimmerman Date: Wed, 13 Aug 2025 12:13:50 +0000 Subject: [PATCH] refspec: Detect DEL character in is_valid_name Prior to this patch the code correctly barfed on control characters with values lower than \040 (space), but failed to account for DEL. This patch fixes the behavior to be consistent with git [1]: > They cannot have ASCII control characters (i.e. bytes whose values are > lower than \040, or \177 DEL) [1]: https://git-scm.com/docs/git-check-ref-format#_description --- src/libgit2/refs.c | 2 +- tests/libgit2/refs/isvalidname.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libgit2/refs.c b/src/libgit2/refs.c index e01278521..fd0c292ff 100644 --- a/src/libgit2/refs.c +++ b/src/libgit2/refs.c @@ -819,7 +819,7 @@ int git_reference_list( static int is_valid_ref_char(char ch) { - if ((unsigned) ch <= ' ') + if ((unsigned) ch <= ' ' || ch == '\177') /* ASCII control characters */ return 0; switch (ch) { diff --git a/tests/libgit2/refs/isvalidname.c b/tests/libgit2/refs/isvalidname.c index 063f0f798..2e20c67bd 100644 --- a/tests/libgit2/refs/isvalidname.c +++ b/tests/libgit2/refs/isvalidname.c @@ -21,6 +21,7 @@ void test_refs_isvalidname__can_detect_invalid_formats(void) cl_assert_equal_i(false, is_valid_name("/")); cl_assert_equal_i(false, is_valid_name("//")); cl_assert_equal_i(false, is_valid_name("")); + cl_assert_equal_i(false, is_valid_name("refs/heads/\177")); cl_assert_equal_i(false, is_valid_name("refs/heads/sub.lock/webmatrix")); }