File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Expand file tree Collapse file tree 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)
416416 return -1 ;
417417}
418418
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+
419438int git_tree__parse (void * _tree , git_odb_object * odb_obj )
420439{
421440 git_tree * tree = _tree ;
@@ -430,14 +449,11 @@ int git_tree__parse(void *_tree, git_odb_object *odb_obj)
430449 git_tree_entry * entry ;
431450 size_t filename_len ;
432451 const char * nul ;
433- int attr ;
452+ unsigned int attr ;
434453
435- if (git__strtol32 (& attr , buffer , & buffer , 8 ) < 0 || !buffer )
454+ if (parse_mode (& attr , buffer , & buffer ) < 0 || !buffer )
436455 return tree_error ("Failed to parse tree. Can't parse filemode" , NULL );
437456
438- if (* buffer ++ != ' ' )
439- return tree_error ("Failed to parse tree. Object is corrupted" , NULL );
440-
441457 if ((nul = memchr (buffer , 0 , buffer_end - buffer )) == NULL )
442458 return tree_error ("Failed to parse tree. Object is corrupted" , NULL );
443459
You can’t perform that action at this time.
0 commit comments