@@ -163,8 +163,10 @@ static void handle_content_type(struct mailinfo *mi, struct strbuf *line)
163
163
if (slurp_attr (line -> buf , "boundary=" , boundary )) {
164
164
strbuf_insert (boundary , 0 , "--" , 2 );
165
165
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 ;
168
170
}
169
171
* (mi -> content_top ) = boundary ;
170
172
boundary = NULL ;
@@ -355,9 +357,11 @@ static int convert_to_utf8(struct mailinfo *mi,
355
357
if (same_encoding (mi -> metainfo_charset , charset ))
356
358
return 0 ;
357
359
out = reencode_string (line -> buf , mi -> metainfo_charset , charset );
358
- if (!out )
360
+ if (!out ) {
361
+ mi -> input_error = -1 ;
359
362
return error ("cannot convert from %s to %s" ,
360
363
charset , mi -> metainfo_charset );
364
+ }
361
365
strbuf_attach (line , out , strlen (out ), strlen (out ));
362
366
return 0 ;
363
367
}
@@ -367,6 +371,7 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
367
371
char * in , * ep , * cp ;
368
372
struct strbuf outbuf = STRBUF_INIT , * dec ;
369
373
struct strbuf charset_q = STRBUF_INIT , piecebuf = STRBUF_INIT ;
374
+ int found_error = 1 ; /* pessimism */
370
375
371
376
in = it -> buf ;
372
377
while (in - it -> buf <= it -> len && (ep = strstr (in , "=?" )) != NULL ) {
@@ -436,10 +441,14 @@ static void decode_header(struct mailinfo *mi, struct strbuf *it)
436
441
strbuf_addstr (& outbuf , in );
437
442
strbuf_reset (it );
438
443
strbuf_addbuf (it , & outbuf );
444
+ found_error = 0 ;
439
445
release_return :
440
446
strbuf_release (& outbuf );
441
447
strbuf_release (& charset_q );
442
448
strbuf_release (& piecebuf );
449
+
450
+ if (found_error )
451
+ mi -> input_error = -1 ;
443
452
}
444
453
445
454
static int check_header (struct mailinfo * mi ,
@@ -640,7 +649,7 @@ static int handle_commit_msg(struct mailinfo *mi, struct strbuf *line)
640
649
641
650
/* normalize the log message to UTF-8. */
642
651
if (convert_to_utf8 (mi , line , mi -> charset .buf ))
643
- exit ( 128 );
652
+ return 0 ; /* mi->input_error already set */
644
653
645
654
if (mi -> use_scissors && is_scissors_line (line )) {
646
655
int i ;
@@ -785,12 +794,15 @@ static int handle_boundary(struct mailinfo *mi, struct strbuf *line)
785
794
will fail first. But just in case..
786
795
*/
787
796
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 ;
791
801
}
792
802
handle_filter (mi , & newline );
793
803
strbuf_release (& newline );
804
+ if (mi -> input_error )
805
+ return 0 ;
794
806
795
807
/* skip to the next boundary */
796
808
if (!find_boundary (mi , line ))
@@ -875,6 +887,8 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line)
875
887
handle_filter (mi , line );
876
888
}
877
889
890
+ if (mi -> input_error )
891
+ break ;
878
892
} while (!strbuf_getwholeline (line , mi -> input , '\n' ));
879
893
880
894
handle_body_out :
@@ -968,7 +982,7 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch)
968
982
969
983
handle_info (mi );
970
984
strbuf_release (& line );
971
- return 0 ;
985
+ return mi -> input_error ;
972
986
}
973
987
974
988
static int git_mailinfo_config (const char * var , const char * value , void * mi_ )
0 commit comments