@@ -593,21 +593,6 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)
593
593
return strbuf_detach (& buf , NULL );
594
594
}
595
595
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
-
611
596
/*
612
597
* Return zero if a and b are equal up to n bytes and nonzero if they are not.
613
598
* 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)
622
607
return res ;
623
608
}
624
609
625
- static const char * check_nonce (const char * buf , size_t len )
610
+ static const char * check_nonce (const char * buf )
626
611
{
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 ;
628
615
timestamp_t stamp , ostamp ;
629
616
char * bohmac , * expect = NULL ;
630
617
const char * retval = NONCE_BAD ;
631
- size_t noncelen ;
632
618
633
619
if (!nonce ) {
634
620
retval = NONCE_MISSING ;
@@ -670,7 +656,6 @@ static const char *check_nonce(const char *buf, size_t len)
670
656
goto leave ;
671
657
}
672
658
673
- noncelen = strlen (nonce );
674
659
expect = prepare_push_cert_nonce (service_dir , stamp );
675
660
if (noncelen != strlen (expect )) {
676
661
/* This is not even the right size. */
@@ -718,35 +703,28 @@ static const char *check_nonce(const char *buf, size_t len)
718
703
static int check_cert_push_options (const struct string_list * push_options )
719
704
{
720
705
const char * buf = push_cert .buf ;
721
- int len = push_cert .len ;
722
706
723
- char * option ;
724
- const char * next_line ;
707
+ const char * option ;
708
+ size_t optionlen ;
725
709
int options_seen = 0 ;
726
710
727
711
int retval = 1 ;
728
712
729
- if (!len )
713
+ if (!* buf )
730
714
return 1 ;
731
715
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 ;
735
718
options_seen ++ ;
736
719
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 ;
743
723
}
744
724
745
725
if (options_seen != push_options -> nr )
746
726
retval = 0 ;
747
727
748
- leave :
749
- free (option );
750
728
return retval ;
751
729
}
752
730
@@ -773,7 +751,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
773
751
check_signature (& sigcheck , push_cert .buf + bogs ,
774
752
push_cert .len - bogs );
775
753
776
- nonce_status = check_nonce (push_cert . buf , bogs );
754
+ nonce_status = check_nonce (sigcheck . payload );
777
755
}
778
756
if (!is_null_oid (& push_cert_oid )) {
779
757
strvec_pushf (& proc -> env , "GIT_PUSH_CERT=%s" ,
0 commit comments