File tree 1 file changed +21
-5
lines changed 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -416,6 +416,25 @@ static int tree_error(const char *str, const char *path)
416
416
return -1 ;
417
417
}
418
418
419
+ static int parse_mode (unsigned int * modep , const char * buffer , const char * * buffer_out )
420
+ {
421
+ unsigned char c ;
422
+ unsigned int mode = 0 ;
423
+
424
+ if (* buffer == ' ' )
425
+ return -1 ;
426
+
427
+ while ((c = * buffer ++ ) != ' ' ) {
428
+ if (c < '0' || c > '7' )
429
+ return -1 ;
430
+ mode = (mode << 3 ) + (c - '0' );
431
+ }
432
+ * modep = mode ;
433
+ * buffer_out = buffer ;
434
+
435
+ return 0 ;
436
+ }
437
+
419
438
int git_tree__parse (void * _tree , git_odb_object * odb_obj )
420
439
{
421
440
git_tree * tree = _tree ;
@@ -430,14 +449,11 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj)
430
449
git_tree_entry * entry ;
431
450
size_t filename_len ;
432
451
const char * nul ;
433
- int attr ;
452
+ unsigned int attr ;
434
453
435
- if (git__strtol32 (& attr , buffer , & buffer , 8 ) < 0 || !buffer )
454
+ if (parse_mode (& attr , buffer , & buffer ) < 0 || !buffer )
436
455
return tree_error ("Failed to parse tree. Can't parse filemode" , NULL );
437
456
438
- if (* buffer ++ != ' ' )
439
- return tree_error ("Failed to parse tree. Object is corrupted" , NULL );
440
-
441
457
if ((nul = memchr (buffer , 0 , buffer_end - buffer )) == NULL )
442
458
return tree_error ("Failed to parse tree. Object is corrupted" , NULL );
443
459
You can’t perform that action at this time.
0 commit comments