fixes for committer/author parsing/check
cover fixes for committer/author parsing/check
fast-import part is clear and should be safe to apply. The test script is a bit ugly as it uses fsck and prune on a shared (with nearby tests) repo. But it should work, any hints on simplifying it are welcome.
fsck part fixes an uncaught bad committer, but also changes error messages for some of bad committer strings. The messages choice is a subject for discussion most likely.
Dmitry Ivankov (5):
fast-import: add input format tests
fast-import: don't fail on omitted committer name
fast-import: check committer name more strictly
fsck: add a few committer name tests
fsck: improve committer/author check
fast-import.c | 33 ++++++++++------ fsck.c | 10 +++-- t/t1450-fsck.sh | 24 ++++++++++++ t/t9300-fast-import.sh | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 150 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.3.4
PATCH 1/5 fast-import: add input format tests
Documentation/git-fast-import.txt says that git-fast-import is strict about it's input format. But committer/author field parsing is a bit loose. Invalid values can be unnoticed and written out to the commit, either with format-conforming input or with non-format-conforming one.
Add one passing and one failing test for empty/absent committer name with well-formed input. And a failed test with unnoticed ill-formed input.
--- t/t9300-fast-import.sh | 99 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 99 insertions(+), 0 deletions(-)
t/t9300-fast-import.sh +99 -0
@@ -324,6 +324,105 @@ test_expect_success \ test `git rev-parse master` = `git rev-parse TEMP_TAG^`' rm -f .git/TEMP_TAG +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/empty-committer-1 +committer <> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: accept empty committer' ' + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" +' +git update-ref -d refs/heads/empty-committer-1 || true + +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/empty-committer-2 +committer <[email protected]> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: accept and fixup committer with no name' ' + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" +' +git update-ref -d refs/heads/empty-committer-2 || true + +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name email> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: fail on invalid committer (1)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <e<mail> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: fail on invalid committer (2)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <email>> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: fail on invalid committer (3)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <email $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: fail on invalid committer (4)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name<email> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_failure 'B: fail on invalid committer (5)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + ### ### series C ###
Signature · 1 line
1.7.3.4
PATCH 2/5 fast-import: don't fail on omitted committer name
In reply to Dmitry Ivankovfast-import format declares 'committer_name SP' to be optional. But SP between empty or not name and a email is obligatory and checked by git-fsck, so fast-import must prepend the SP if the name is omitted. Currently it doesn't.
Name cannot contain LT or GT and ident always comes after SP in fast-import. So reuse that SP as if a valid 'SP <email>' ident was passed.
This fixes a ident parsing bug for a well-formed fast-import input. Though the parsing is still loose and can accept a ill-formed input.
--- fast-import.c | 4 ++++ t/t9300-fast-import.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)
fast-import.c +4 -0
@@ -1972,6 +1972,10 @@ static char *parse_ident(const char *buf)size_t name_len;char *ident; +/* ensure there is a space delimiter even if there is no name */ +if (*buf =='<' ) + --buf; + gt =strrchr (buf,'>' );if (!gt)die ("Missing > in ident string: %s" , buf);
t/t9300-fast-import.sh +1 -1
@@ -352,7 +352,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: accept and fixup committer with no name' ' +test_expect_success 'B: accept and fixup committer with no name' ' git fast-import <input && out=$(git fsck) && echo "$out" &&
Signature · 1 line
1.7.3.4
Re: [PATCH 2/5] fast-import: don't fail on omitted committer name
Quoted 2 lines · Dmitry Ivankov
fast-import format declares '
committer_nameSP' to be optional. But SP between empty or not name and a email is obligatory and checked by
Sorry, cannot parse this.
Quoted 43 lines
git-fsck, so fast-import must prepend the SP if the name is omitted. Currently it doesn't.
Name cannot contain LT or GT and ident always comes after SP in fast-import. So reuse that SP as if a valid 'SP <email>' ident was passed.
This fixes a ident parsing bug for a well-formed fast-import input. Though the parsing is still loose and can accept a ill-formed input.
Signed-off-by Dmitry Ivankov <[email protected]>--- fast-import.c | 4 ++++ t/t9300-fast-import.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletions(-)fast-import.c +4
-0@@ -1972,6 +1972,10 @@ static char *parse_ident(const char *buf)size_t name_len;char *ident; +/* ensure there is a space delimiter even if there is no name */ +if (*buf =='<' ) + --buf; + gt =strrchr (buf,'>' );if (!gt)die ("Missing > in ident string: %s" , buf);t/t9300-fast-import.sh +1
-1@@ -352,7 +352,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: accept and fixup committer with no name' ' +test_expect_success 'B: accept and fixup committer with no name' ' git fast-import <input && out=$(git fsck) && echo "$out" &&
Re: [PATCH 2/5] fast-import: don't fail on omitted committer name
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Dmitry Ivankov
fast-import format declares '
committer_nameSP' to be optional. But SP between empty or not name and a email is obligatory and checked bySorry, cannot parse this.
Ok, the point is fast-import input format for identities is declared to be '(name SP)? LT email GT' (followed by a datetime)
where name and email are allowed to be empty (and should not have LF, LT, GT characters).
While git-fsck checks identities to be in form
'name SP LT email GT' (followed by a datetime)
where name and email are allowed to be empty (and should not have LF, LT, GT characters).
So fast-import must prepend a space if the name part is omitted. This patch makes it do so.
Quoted 45 lines
Quoted 44 lines
git-fsck, so fast-import must prepend the SP if the name is omitted. Currently it doesn't.
Name cannot contain LT or GT and ident always comes after SP in fast-import. So reuse that SP as if a valid 'SP <email>' ident was passed.
This fixes a ident parsing bug for a well-formed fast-import input. Though the parsing is still loose and can accept a ill-formed input.
Signed-off-by Dmitry Ivankov <[email protected]>---
fast-import.c | 4 ++++
t/t9300-fast-import.sh | 2 +-2 files changed, 5 insertions(+), 1 deletions(-)fast-import.c +4
-0@@ -1972,6 +1972,10 @@ static char *parse_ident(const char *buf) size_t name_len; char *ident; + /* ensure there is a space delimiter even if there is no name */ + if (*buf == '<') + --buf; + gt = strrchr(buf, '>'); if (!gt) die("Missing > in ident string: %s", buf);t/t9300-fast-import.sh +0
-0@@ -352,7 +352,7 @@ data <<COMMITempty commit
COMMIT
INPUT_ENDt/t9300-fast-import.sh +1
-1-test_expect_failure 'B: accept and fixup committer with no name' ' +test_expect_success 'B: accept and fixup committer with no name' 'git fast-import <input &&
out=$(git fsck) &&
echo "$out" &&
PATCH 3/5 fast-import: check committer name more strictly
In reply to Dmitry Ivankov--- fast-import.c | 29 +++++++++++++++++------------ t/t9300-fast-import.sh | 10 +++++----- 2 files changed, 22 insertions(+), 17 deletions(-)
fast-import.c +17 -12
@@ -1968,7 +1968,7 @@ static int validate_raw_date(const char *src, char *result, int maxlen)static char *parse_ident (const char *buf) { -const char *gt; +const char *ltgt;size_t name_len;char *ident;
@@ -1976,28 +1976,33 @@ static char *parse_ident(const char *buf)if (*buf =='<' ) --buf; - gt =strrchr (buf,'>' ); -if (!gt) + ltgt = buf +strcspn (buf,"<>" ); +if (*ltgt !='<' ) +die ("Missing < in ident string: %s" , buf); +if (ltgt != buf && ltgt[-1 ] !=' ' ) +die ("Missing space before < in ident string: %s" , buf); + ltgt = ltgt +1 +strcspn (ltgt +1 ,"<>" ); +if (*ltgt !='>' )die ("Missing > in ident string: %s" , buf); - gt++; -if (*gt !=' ' ) + ltgt++; +if (*ltgt !=' ' )die ("Missing space after > in ident string: %s" , buf); - gt++; - name_len = gt - buf; + ltgt++; + name_len = ltgt - buf; ident =xmalloc (name_len +24 );strncpy (ident, buf, name_len);switch (whenspec) {case WHENSPEC_RAW : -if (validate_raw_date (gt, ident + name_len,24 ) <0 ) -die ("Invalid raw date \"%s\" in ident: %s" , gt, buf); +if (validate_raw_date (ltgt, ident + name_len,24 ) <0 ) +die ("Invalid raw date \"%s\" in ident: %s" , ltgt, buf);break ;case WHENSPEC_RFC2822 : -if (parse_date (gt, ident + name_len,24 ) <0 ) -die ("Invalid rfc2822 date \"%s\" in ident: %s" , gt, buf); +if (parse_date (ltgt, ident + name_len,24 ) <0 ) +die ("Invalid rfc2822 date \"%s\" in ident: %s" , ltgt, buf);break ;case WHENSPEC_NOW : -if (strcmp ("now" , gt)) +if (strcmp ("now" , ltgt))die ("Date in ident must be 'now': %s" , buf);datestamp (ident + name_len,24 );break ;
t/t9300-fast-import.sh +5 -5
@@ -370,7 +370,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: fail on invalid committer (1)' ' +test_expect_success 'B: fail on invalid committer (1)' ' test_must_fail git fast-import <input ' git update-ref -d refs/heads/invalid-committer || true
@@ -382,7 +382,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: fail on invalid committer (2)' ' +test_expect_success 'B: fail on invalid committer (2)' ' test_must_fail git fast-import <input ' git update-ref -d refs/heads/invalid-committer || true
@@ -394,7 +394,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: fail on invalid committer (3)' ' +test_expect_success 'B: fail on invalid committer (3)' ' test_must_fail git fast-import <input ' git update-ref -d refs/heads/invalid-committer || true
@@ -406,7 +406,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: fail on invalid committer (4)' ' +test_expect_success 'B: fail on invalid committer (4)' ' test_must_fail git fast-import <input ' git update-ref -d refs/heads/invalid-committer || true
@@ -418,7 +418,7 @@ data <<COMMIT empty commit COMMIT INPUT_END -test_expect_failure 'B: fail on invalid committer (5)' ' +test_expect_success 'B: fail on invalid committer (5)' ' test_must_fail git fast-import <input ' git update-ref -d refs/heads/invalid-committer || true
Signature · 1 line
1.7.3.4
Re: [PATCH 3/5] fast-import: check committer name more strictly
Quoted 2 lines · Dmitry Ivankov
Signed-off-by Dmitry Ivankov <[email protected]>---
Please describe how you check this field "more strictly" in the body of the log message, iow, against what rule you are validating, perhaps something like:
The identifier must be either "<address>" or "Name <address>" where neither address nor Name can contain '<' nor '>'; otherwise the input stream is rejected.
As fast-import is used to _create_ new objects, its input is a simple text file that can be fixed-up as needed, it is a good idea to validate the input more strictly and rejecting bad ones.
PATCH 4/5 fsck: add a few committer name tests
In reply to Dmitry Ivankovfsck reports "missing space before <email>" for committer string equal to "name email>". It'd be nicer to say "missing < in email" or "name is bad" (has > in it). The second option looks a bit better, add such a failing test.
For "name> <email>" no error is reported. Looks like a bug, so add such a failing test."
--- t/t1450-fsck.sh | 24 ++++++++++++++++++++++++ 1 files changed, 24 insertions(+), 0 deletions(-)
t/t1450-fsck.sh +24 -0
@@ -110,6 +110,30 @@ test_expect_success 'email with embedded > is not okay' ' grep "error in commit $new" out ' +test_expect_failure 'missing < email delimiter is reported nicely' ' + git cat-file commit HEAD >basis && + sed "s/<//" basis >bad-email-2 && + new=$(git hash-object -t commit -w --stdin <bad-email-2) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new.* - bad name" out +' + +test_expect_failure '> in name is reported' ' + git cat-file commit HEAD >basis && + sed "s/ </> </" basis >bad-email-3 && + new=$(git hash-object -t commit -w --stdin <bad-email-3) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new" out +' + test_expect_success 'tag pointing to nonexistent' ' cat >invalid-tag <<-\EOF && object ffffffffffffffffffffffffffffffffffffffff
Signature · 1 line
1.7.3.4
PATCH 5/5 fsck: improve committer/author check
In reply to Dmitry IvankovNeither name nor email should contain < or >, so split the string with these and check they come in that order and < is preceeded with a space.
If < is missing don't say a confusing "missing space", say "bad name" if
Quoted 1 line
isn't missing and "missing email" if both < and > are missing.
--- fsck.c | 10 ++++++---- t/t1450-fsck.sh | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-)
fsck.c +6 -4
@@ -224,13 +224,15 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)static int fsck_ident (char **ident,struct object *obj,fsck_error error_func) { -if (**ident =='<' || **ident =='\n' ) -return error_func (obj,FSCK_ERROR ,"invalid author/committer line - missing space before email" ); - *ident +=strcspn (*ident,"<\n" ); -if ((*ident)[-1 ] !=' ' ) +if (**ident =='<' )return error_func (obj,FSCK_ERROR ,"invalid author/committer line - missing space before email" ); + *ident +=strcspn (*ident,"<>\n" ); +if (**ident =='>' ) +return error_func (obj,FSCK_ERROR ,"invalid author/committer line - bad name" );if (**ident !='<' )return error_func (obj,FSCK_ERROR ,"invalid author/committer line - missing email" ); +if ((*ident)[-1 ] !=' ' ) +return error_func (obj,FSCK_ERROR ,"invalid author/committer line - missing space before email" ); (*ident)++; *ident +=strcspn (*ident,"<>\n" );if (**ident !='>' )
t/t1450-fsck.sh +2 -2
@@ -110,7 +110,7 @@ test_expect_success 'email with embedded > is not okay' ' grep "error in commit $new" out ' -test_expect_failure 'missing < email delimiter is reported nicely' ' +test_expect_success 'missing < email delimiter is reported nicely' ' git cat-file commit HEAD >basis && sed "s/<//" basis >bad-email-2 && new=$(git hash-object -t commit -w --stdin <bad-email-2) &&
@@ -122,7 +122,7 @@ test_expect_failure 'missing < email delimiter is reported nicely' ' grep "error in commit $new.* - bad name" out ' -test_expect_failure '> in name is reported' ' +test_expect_success '> in name is reported' ' git cat-file commit HEAD >basis && sed "s/ </> </" basis >bad-email-3 && new=$(git hash-object -t commit -w --stdin <bad-email-3) &&
Signature · 1 line
1.7.3.4
Re: [PATCH 5/5] fsck: improve committer/author check
Quoted 8 lines · Dmitry Ivankov
Neither name nor email should contain < or >, so split the string with these and check they come in that order and < is preceeded with a space.
If < is missing don't say a confusing "missing space", say "bad name" if
Quoted 1 line
isn't missing and "missing email" if both < and > are missing.
Signed-off-by Dmitry Ivankov <[email protected]>---
Same comment as 3/5; before starting to talk about how you implemented your validation, please state what rules you are enforcing.
Thanks.
Re: [PATCH 5/5] fsck: improve committer/author check
Quoted 5 lines · Junio C Hamano
Quoted 3 lines · Dmitry Ivankov
Neither name nor email should contain < or >, so split the string with these and check they come in that order and < is preceeded with a space.
Quoted 8 lines
Quoted 5 lines
If < is missing don't say a confusing "missing space", say "bad name" if
Quoted 1 line
isn't missing and "missing email" if both < and > are missing.
Signed-off-by Dmitry Ivankov <[email protected]>---
Same comment as 3/5; before starting to talk about how you implemented your validation, please state what rules you are enforcing.
Thanks, will apply and reroll.
But before this, is it ok to reject "Name> <email>" idents in fsck and fast-import?
fsck already denies '<' and '>' inside email, and '<' in name. But accepts '>' in name.
It just hit me that Documentation/fast-import.c doesn't deny '>' in name and it is
consistent with fsck, so there may be a reason behind it.
Quoted 3 lines
Thanks.