@@ -654,6 +654,7 @@ static int write_author_script(const char *message)
654
654
strbuf_addch (& buf , * (message ++ ));
655
655
else
656
656
strbuf_addf (& buf , "'\\\\%c'" , * (message ++ ));
657
+ strbuf_addch (& buf , '\'' );
657
658
res = write_message (buf .buf , buf .len , rebase_path_author_script (), 1 );
658
659
strbuf_release (& buf );
659
660
return res ;
@@ -708,14 +709,16 @@ static const char *read_author_ident(struct strbuf *buf)
708
709
const char * keys [] = {
709
710
"GIT_AUTHOR_NAME=" , "GIT_AUTHOR_EMAIL=" , "GIT_AUTHOR_DATE="
710
711
};
711
- char * in , * out , * eol ;
712
- int i = 0 , len ;
712
+ struct strbuf out = STRBUF_INIT ;
713
+ char * in , * eol ;
714
+ const char * val [3 ];
715
+ int i = 0 ;
713
716
714
717
if (strbuf_read_file (buf , rebase_path_author_script (), 256 ) <= 0 )
715
718
return NULL ;
716
719
717
720
/* dequote values and construct ident line in-place */
718
- for (in = out = buf -> buf ; i < 3 && in - buf -> buf < buf -> len ; i ++ ) {
721
+ for (in = buf -> buf ; i < 3 && in - buf -> buf < buf -> len ; i ++ ) {
719
722
if (!skip_prefix (in , keys [i ], (const char * * )& in )) {
720
723
warning (_ ("could not parse '%s' (looking for '%s'" ),
721
724
rebase_path_author_script (), keys [i ]);
@@ -724,17 +727,12 @@ static const char *read_author_ident(struct strbuf *buf)
724
727
725
728
eol = strchrnul (in , '\n' );
726
729
* eol = '\0' ;
727
- sq_dequote (in );
728
- len = strlen (in );
729
-
730
- if (i > 0 ) /* separate values by spaces */
731
- * (out ++ ) = ' ' ;
732
- if (i == 1 ) /* email needs to be surrounded by <...> */
733
- * (out ++ ) = '<' ;
734
- memmove (out , in , len );
735
- out += len ;
736
- if (i == 1 ) /* email needs to be surrounded by <...> */
737
- * (out ++ ) = '>' ;
730
+ if (!sq_dequote (in )) {
731
+ warning (_ ("bad quoting on %s value in '%s'" ),
732
+ keys [i ], rebase_path_author_script ());
733
+ return NULL ;
734
+ }
735
+ val [i ] = in ;
738
736
in = eol + 1 ;
739
737
}
740
738
@@ -744,7 +742,18 @@ static const char *read_author_ident(struct strbuf *buf)
744
742
return NULL ;
745
743
}
746
744
747
- buf -> len = out - buf -> buf ;
745
+ /* validate date since fmt_ident() will die() on bad value */
746
+ if (parse_date (val [2 ], & out )){
747
+ warning (_ ("invalid date format '%s' in '%s'" ),
748
+ val [2 ], rebase_path_author_script ());
749
+ strbuf_release (& out );
750
+ return NULL ;
751
+ }
752
+
753
+ strbuf_reset (& out );
754
+ strbuf_addstr (& out , fmt_ident (val [0 ], val [1 ], val [2 ], 0 ));
755
+ strbuf_swap (buf , & out );
756
+ strbuf_release (& out );
748
757
return buf -> buf ;
749
758
}
750
759
0 commit comments