@@ -163,8 +163,10 @@ static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
163163 if (slurp_attr (line -> buf , "boundary=" , boundary )) {
164164 strbuf_insert (boundary , 0 , "--" , 2 );
165165 if (++ mi -> content_top >= & mi -> content [MAX_BOUNDARIES ]) {
166- fprintf (stderr , "Too many boundaries to handle\n" );
167- exit (1 );
166+ error ("Too many boundaries to handle" );
167+ mi -> input_error = -1 ;
168+ mi -> content_top = & mi -> content [MAX_BOUNDARIES ] - 1 ;
169+ return ;
168170 }
169171 * (mi -> content_top ) = boundary ;
170172 boundary = NULL ;
@@ -355,9 +357,11 @@ static int convert_to_utf8(struct mailinfo *mi,
355357 if (same_encoding (mi -> metainfo_charset , charset ))
356358 return 0 ;
357359 out = reencode_string (line -> buf , mi -> metainfo_charset , charset );
358- if (!out )
360+ if (!out ) {
361+ mi -> input_error = -1 ;
359362 return error ("cannot convert from %s to %s" ,
360363 charset , mi -> metainfo_charset );
364+ }
361365 strbuf_attach (line , out , strlen (out ), strlen (out ));
362366 return 0 ;
363367}
@@ -367,6 +371,7 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
367371 char * in , * ep , * cp ;
368372 struct strbuf outbuf = STRBUF_INIT , * dec ;
369373 struct strbuf charset_q = STRBUF_INIT , piecebuf = STRBUF_INIT ;
374+ int found_error = 1 ; /* pessimism */
370375
371376 in = it -> buf ;
372377 while (in - it -> buf <= it -> len && (ep = strstr (in , "=?" )) != NULL ) {
@@ -436,10 +441,14 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
436441 strbuf_addstr (& outbuf , in );
437442 strbuf_reset (it );
438443 strbuf_addbuf (it , & outbuf );
444+ found_error = 0 ;
439445release_return :
440446 strbuf_release (& outbuf );
441447 strbuf_release (& charset_q );
442448 strbuf_release (& piecebuf );
449+
450+ if (found_error )
451+ mi -> input_error = -1 ;
443452}
444453
445454static int check_header (struct mailinfo * mi ,
@@ -640,7 +649,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
640649
641650 /* normalize the log message to UTF-8. */
642651 if (convert_to_utf8 (mi , line , mi -> charset .buf ))
643- exit ( 128 );
652+ return 0 ; /* mi->input_error already set */
644653
645654 if (mi -> use_scissors && is_scissors_line (line )) {
646655 int i ;
@@ -785,12 +794,15 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
785794 will fail first. But just in case..
786795 */
787796 if (-- mi -> content_top < mi -> content ) {
788- fprintf (stderr , "Detected mismatched boundaries, "
789- "can't recover\n" );
790- exit (1 );
797+ error ("Detected mismatched boundaries, can't recover" );
798+ mi -> input_error = -1 ;
799+ mi -> content_top = mi -> content ;
800+ return 0 ;
791801 }
792802 handle_filter (mi , & newline );
793803 strbuf_release (& newline );
804+ if (mi -> input_error )
805+ return 0 ;
794806
795807 /* skip to the next boundary */
796808 if (!find_boundary (mi , line ))
@@ -875,6 +887,8 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
875887 handle_filter (mi , line );
876888 }
877889
890+ if (mi -> input_error )
891+ break ;
878892 } while (!strbuf_getwholeline (line , mi -> input , '\n' ));
879893
880894handle_body_out :
@@ -968,7 +982,7 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
968982
969983 handle_info (mi );
970984 strbuf_release (& line );
971- return 0 ;
985+ return mi -> input_error ;
972986}
973987
974988static int git_mailinfo_config (const char * var , const char * value , void * mi_ )
0 commit comments