@@ -222,12 +222,47 @@ static int fsck_tree(struct tree *item, int strict, fsck_error error_func)
222
222
return retval ;
223
223
}
224
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 ] != ' ' )
231
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing space before email" );
232
+ if (* * ident != '<' )
233
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing email" );
234
+ (* ident )++ ;
235
+ * ident += strcspn (* ident , "<>\n" );
236
+ if (* * ident != '>' )
237
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad email" );
238
+ (* ident )++ ;
239
+ if (* * ident != ' ' )
240
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - missing space before date" );
241
+ (* ident )++ ;
242
+ if (* * ident == '0' && (* ident )[1 ] != ' ' )
243
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - zero-padded date" );
244
+ * ident += strspn (* ident , "0123456789" );
245
+ if (* * ident != ' ' )
246
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad date" );
247
+ (* ident )++ ;
248
+ if ((* * ident != '+' && * * ident != '-' ) ||
249
+ !isdigit ((* ident )[1 ]) ||
250
+ !isdigit ((* ident )[2 ]) ||
251
+ !isdigit ((* ident )[3 ]) ||
252
+ !isdigit ((* ident )[4 ]) ||
253
+ ((* ident )[5 ] != '\n' ))
254
+ return error_func (obj , FSCK_ERROR , "invalid author/committer line - bad time zone" );
255
+ (* ident ) += 6 ;
256
+ return 0 ;
257
+ }
258
+
225
259
static int fsck_commit (struct commit * commit , fsck_error error_func )
226
260
{
227
261
char * buffer = commit -> buffer ;
228
262
unsigned char tree_sha1 [20 ], sha1 [20 ];
229
263
struct commit_graft * graft ;
230
264
int parents = 0 ;
265
+ int err ;
231
266
232
267
if (commit -> date == ULONG_MAX )
233
268
return error_func (& commit -> object , FSCK_ERROR , "invalid author/committer line" );
@@ -266,6 +301,18 @@ static int fsck_commit(struct commit *commit, fsck_error error_func)
266
301
}
267
302
if (memcmp (buffer , "author " , 7 ))
268
303
return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected 'author' line" );
304
+ buffer += 7 ;
305
+ err = fsck_ident (& buffer , & commit -> object , error_func );
306
+ if (err )
307
+ return err ;
308
+ if (memcmp (buffer , "committer " , strlen ("committer " )))
309
+ return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected 'committer' line" );
310
+ buffer += strlen ("committer " );
311
+ err = fsck_ident (& buffer , & commit -> object , error_func );
312
+ if (err )
313
+ return err ;
314
+ if (* buffer != '\n' )
315
+ return error_func (& commit -> object , FSCK_ERROR , "invalid format - expected blank line" );
269
316
if (!commit -> tree )
270
317
return error_func (& commit -> object , FSCK_ERROR , "could not load commit's tree %s" , sha1_to_hex (tree_sha1 ));
271
318
0 commit comments