@@ -593,21 +593,6 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
593593 return strbuf_detach (& buf , NULL );
594594}
595595
596- static char * find_header (const char * msg , size_t len , const char * key ,
597- const char * * next_line )
598- {
599- size_t out_len ;
600- const char * val = find_header_mem (msg , len , key , & out_len );
601-
602- if (!val )
603- return NULL ;
604-
605- if (next_line )
606- * next_line = val + out_len + 1 ;
607-
608- return xmemdupz (val , out_len );
609- }
610-
611596/*
612597 * Return zero if a and b are equal up to n bytes and nonzero if they are not.
613598 * This operation is guaranteed to run in constant time to avoid leaking data.
@@ -622,13 +607,14 @@ static int constant_memequal(const char *a, const char *b, size_t n)
622607 return res ;
623608}
624609
625- static const char * check_nonce (const char * buf , size_t len )
610+ static const char * check_nonce (const char * buf )
626611{
627- char * nonce = find_header (buf , len , "nonce" , NULL );
612+ size_t noncelen ;
613+ const char * found = find_commit_header (buf , "nonce" , & noncelen );
614+ char * nonce = found ? xmemdupz (found , noncelen ) : NULL ;
628615 timestamp_t stamp , ostamp ;
629616 char * bohmac , * expect = NULL ;
630617 const char * retval = NONCE_BAD ;
631- size_t noncelen ;
632618
633619 if (!nonce ) {
634620 retval = NONCE_MISSING ;
@@ -670,7 +656,6 @@ static const char *check_nonce(const char *buf, size_t len)
670656 goto leave ;
671657 }
672658
673- noncelen = strlen (nonce );
674659 expect = prepare_push_cert_nonce (service_dir , stamp );
675660 if (noncelen != strlen (expect )) {
676661 /* This is not even the right size. */
@@ -718,35 +703,28 @@ static const char *check_nonce(const char *buf, size_t len)
718703static int check_cert_push_options (const struct string_list * push_options )
719704{
720705 const char * buf = push_cert .buf ;
721- int len = push_cert .len ;
722706
723- char * option ;
724- const char * next_line ;
707+ const char * option ;
708+ size_t optionlen ;
725709 int options_seen = 0 ;
726710
727711 int retval = 1 ;
728712
729- if (!len )
713+ if (!* buf )
730714 return 1 ;
731715
732- while ((option = find_header (buf , len , "push-option" , & next_line ))) {
733- len -= (next_line - buf );
734- buf = next_line ;
716+ while ((option = find_commit_header (buf , "push-option" , & optionlen ))) {
717+ buf = option + optionlen + 1 ;
735718 options_seen ++ ;
736719 if (options_seen > push_options -> nr
737- || strcmp (option ,
738- push_options -> items [options_seen - 1 ].string )) {
739- retval = 0 ;
740- goto leave ;
741- }
742- free (option );
720+ || xstrncmpz (push_options -> items [options_seen - 1 ].string ,
721+ option , optionlen ))
722+ return 0 ;
743723 }
744724
745725 if (options_seen != push_options -> nr )
746726 retval = 0 ;
747727
748- leave :
749- free (option );
750728 return retval ;
751729}
752730
@@ -773,7 +751,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
773751 check_signature (& sigcheck , push_cert .buf + bogs ,
774752 push_cert .len - bogs );
775753
776- nonce_status = check_nonce (push_cert . buf , bogs );
754+ nonce_status = check_nonce (sigcheck . payload );
777755 }
778756 if (!is_null_oid (& push_cert_oid )) {
779757 strvec_pushf (& proc -> env , "GIT_PUSH_CERT=%s" ,
0 commit comments