Skip to content

Commit

Permalink
Disallow the empty string as an attribute name
Browse files Browse the repository at this point in the history
Previously, it was possible to have a line like "file.txt =foo" in a
.gitattribute file, after which an invocation like "git check-attr ''
-- file.txt" would succeed.  This patch disallows both constructs.

Please note that any existing .gitattributes file that tries to set an
empty attribute will now trigger the error message "error: : not a
valid attribute name" whereas previously the nonsense was allowed
through.

Signed-off-by: Michael Haggerty <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
mhagger authored and gitster committed Aug 4, 2011
1 parent d42453a commit c0b13b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
6 changes: 6 additions & 0 deletions t/t0003-attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit c0b13b2

Please sign in to comment.