@@ -786,29 +786,43 @@ static int gen_pktline(git_str *buf, git_push *push)
786786 push_spec * spec ;
787787 char * option ;
788788 size_t i , len ;
789- char old_id [GIT_OID_SHA1_HEXSIZE + 1 ], new_id [GIT_OID_SHA1_HEXSIZE + 1 ];
790-
791- old_id [GIT_OID_SHA1_HEXSIZE ] = '\0' ; new_id [GIT_OID_SHA1_HEXSIZE ] = '\0' ;
789+ char old_id [GIT_OID_MAX_HEXSIZE + 1 ], new_id [GIT_OID_MAX_HEXSIZE + 1 ];
790+ size_t old_id_len , new_id_len ;
792791
793792 git_vector_foreach (& push -> specs , i , spec ) {
794- len = 2 * GIT_OID_SHA1_HEXSIZE + 7 + strlen (spec -> refspec .dst );
793+ len = strlen (spec -> refspec .dst ) + 7 ;
795794
796795 if (i == 0 ) {
797- ++ len ; /* '\0' */
796+ /* Need a leading \0 */
797+ ++ len ;
798+
798799 if (push -> report_status )
799800 len += strlen (GIT_CAP_REPORT_STATUS ) + 1 ;
801+
800802 if (git_vector_length (& push -> remote_push_options ) > 0 )
801803 len += strlen (GIT_CAP_PUSH_OPTIONS ) + 1 ;
804+
802805 len += strlen (GIT_CAP_SIDE_BAND_64K ) + 1 ;
803806 }
804807
808+ old_id_len = git_oid_hexsize (git_oid_type (& spec -> roid ));
809+ new_id_len = git_oid_hexsize (git_oid_type (& spec -> loid ));
810+
811+ len += (old_id_len + new_id_len );
812+
805813 git_oid_fmt (old_id , & spec -> roid );
814+ old_id [old_id_len ] = '\0' ;
815+
806816 git_oid_fmt (new_id , & spec -> loid );
817+ new_id [new_id_len ] = '\0' ;
807818
808- git_str_printf (buf , "%04" PRIxZ "%s %s %s" , len , old_id , new_id , spec -> refspec .dst );
819+ git_str_printf (buf , "%04" PRIxZ "%.*s %.*s %s" , len ,
820+ (int )old_id_len , old_id , (int )new_id_len , new_id ,
821+ spec -> refspec .dst );
809822
810823 if (i == 0 ) {
811824 git_str_putc (buf , '\0' );
825+
812826 /* Core git always starts their capabilities string with a space */
813827 if (push -> report_status ) {
814828 git_str_putc (buf , ' ' );
@@ -831,6 +845,7 @@ static int gen_pktline(git_str *buf, git_push *push)
831845 git_str_printf (buf , "%04" PRIxZ "%s" , strlen (option ) + 4 , option );
832846 }
833847 }
848+
834849 git_str_puts (buf , "0000" );
835850 return git_str_oom (buf ) ? -1 : 0 ;
836851}
@@ -1176,7 +1191,7 @@ int git_smart__push(git_transport *transport, git_push *push)
11761191#ifdef PUSH_DEBUG
11771192{
11781193 git_remote_head * head ;
1179- char hex [GIT_OID_SHA1_HEXSIZE + 1 ]; hex [GIT_OID_SHA1_HEXSIZE ] = '\0' ;
1194+ char hex [GIT_OID_MAX_HEXSIZE + 1 ], hex [GIT_OID_MAX_HEXSIZE ] = '\0' ;
11801195
11811196 git_vector_foreach (& push -> remote -> refs , i , head ) {
11821197 git_oid_fmt (hex , & head -> oid );
0 commit comments