fsck: improve committer/author check

fsck allows a name with > character in it like "name> <email>". Also for "name email>" fsck says "missing space before email". More precisely, it seeks for a first '<', checks that ' ' preceeds it. Then seeks to '<' or '>' and checks that it is the '>'. Missing space is reported if either '<' is not found or it's not preceeded with ' '. Change it to following. Seek to '<' or '>', check that it is '<' and is preceeded with ' '. Seek to '<' or '>' and check that it is '>'. So now "name> <email>" is rejected as "bad name". More strict name check is the only change in what is accepted. Report 'missing space' only if '<' is found and is not preceeded with a space. Signed-off-by: Dmitry Ivankov <divanorama@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dmitry Ivankov committed Aug 11, 2011 at 16:21 UTC 53f53cff24c5fe6683234bcd5386a447b8b17074
2 files changed +9 -7
fsck.c
+6 -4
@@ -224,13 +224,15 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
224
225 static int fsck_ident(char **ident, struct object *obj, fsck_error error_func)
226 {
227 - if (**ident == '<' || **ident == '\n')
228 - return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
229 - *ident += strcspn(*ident, "<\n");
230 - if ((*ident)[-1] != ' ')
227 + if (**ident == '<')
228 return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
229 + *ident += strcspn(*ident, "<>\n");
230 + if (**ident == '>')
231 + return error_func(obj, FSCK_ERROR, "invalid author/committer line - bad name");
232 if (**ident != '<')
233 return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing email");
234 + if ((*ident)[-1] != ' ')
235 + return error_func(obj, FSCK_ERROR, "invalid author/committer line - missing space before email");
236 (*ident)++;
237 *ident += strcspn(*ident, "<>\n");
238 if (**ident != '>')
t/t1450-fsck.sh
+3 -3
@@ -110,7 +110,7 @@ test_expect_success 'email with embedded > is not okay' '
110 grep "error in commit $new" out
111 '
112
113 -test_expect_failure 'missing < email delimiter is reported nicely' '
113 +test_expect_success 'missing < email delimiter is reported nicely' '
114 git cat-file commit HEAD >basis &&
115 sed "s/<//" basis >bad-email-2 &&
116 new=$(git hash-object -t commit -w --stdin <bad-email-2) &&
@@ -122,7 +122,7 @@ test_expect_failure 'missing < email delimiter is reported nicely' '
122 grep "error in commit $new.* - bad name" out
123 '
124
125 -test_expect_failure 'missing email is reported nicely' '
125 +test_expect_success 'missing email is reported nicely' '
126 git cat-file commit HEAD >basis &&
127 sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 &&
128 new=$(git hash-object -t commit -w --stdin <bad-email-3) &&
@@ -134,7 +134,7 @@ test_expect_failure 'missing email is reported nicely' '
134 grep "error in commit $new.* - missing email" out
135 '
136
137 -test_expect_failure '> in name is reported' '
137 +test_expect_success '> in name is reported' '
138 git cat-file commit HEAD >basis &&
139 sed "s/ </> </" basis >bad-email-4 &&
140 new=$(git hash-object -t commit -w --stdin <bad-email-4) &&