diff --git a/attr.c b/attr.c index 4a1244f9a9b7ec..b1d1d6d791687a 100644 --- a/attr.c +++ b/attr.c @@ -53,7 +53,7 @@ static int invalid_attr_name(const char *name, int namelen) * Attribute name cannot begin with '-' and must consist of * characters from [-A-Za-z0-9_.]. */ - if (*name == '-') + if (namelen <= 0 || *name == '-') return -1; while (namelen--) { char ch = *name++; diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index ebbc7554a7d4dc..8c76b79bb0b9c1 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -42,6 +42,12 @@ test_expect_success 'setup' ' ' +test_expect_success 'command line checks' ' + + test_must_fail git check-attr "" -- f + +' + test_expect_success 'attribute test' ' attr_check f f &&