| | |
| | public function render() { |
| | - if( $this->subPath === 'git-receive-pack' ) { |
| | - http_response_code( 403 ); |
| | - echo "Read-only repository."; |
| | - exit; |
| | - } |
| | - |
| | - if( $this->subPath === 'info/refs' ) { |
| | + if( str_ends_with( $this->subPath, 'info/refs' ) ) { |
| | $this->renderInfoRefs(); |
| | return; |
| | } |
| | |
| | - if( $this->subPath === 'git-upload-pack' ) { |
| | + if( str_ends_with( $this->subPath, 'git-upload-pack' ) ) { |
| | $this->handleUploadPack(); |
| | return; |
| | + } |
| | + |
| | + if( $this->subPath === 'git-receive-pack' ) { |
| | + http_response_code( 403 ); |
| | + echo "Read-only repository."; |
| | + exit; |
| | } |
| | |
 |
| | } |
| | |
| | - $this->serve( $this->subPath, 'text/plain' ); |
| | + http_response_code( 404 ); |
| | + echo "Not Found"; |
| | + exit; |
| | } |
| | |
| | private function renderInfoRefs(): void { |
| | $service = $_GET['service'] ?? ''; |
| | - |
| | - if( $service === 'git-receive-pack' ) { |
| | - http_response_code( 403 ); |
| | - echo "Read-only repository."; |
| | - exit; |
| | - } |
| | |
| | if( $service === 'git-upload-pack' ) { |
 |
| | $this->packetWrite( $refs[$i]['sha'] . " " . $refs[$i]['ref'] . "\n" ); |
| | } |
| | + } else { |
| | + $this->packetWrite( "0000000000000000000000000000000000000000 capabilities^{}\0$caps\n" ); |
| | } |
| | |
| | $this->packetFlush(); |
| | exit; |
| | } |
| | |
| | header( 'Content-Type: text/plain' ); |
| | - |
| | if( $this->git->streamRaw( 'info/refs' ) ) { |
| | exit; |
| | } |
| | |
| | $this->git->eachRef( function( $ref, $sha ) { |
| | echo "$sha\t$ref\n"; |
| | } ); |
| | - |
| | exit; |
| | } |
 |
| | |
| | if( empty( $wants ) ) { |
| | - $this->packetWrite( "ERR no wants provided\n" ); |
| | $this->packetFlush(); |
| | exit; |
 |
| | $chunkSize = 65000; |
| | $offset = 0; |
| | + $len = strlen( $data ); |
| | |
| | - while( $offset < strlen( $data ) ) { |
| | + if ( $len === 0 ) return; |
| | + |
| | + while( $offset < $len ) { |
| | $chunk = substr( $data, $offset, $chunkSize ); |
| | $packet = chr( $band ) . $chunk; |
 |
| | |
| | $lenHex = substr( $input, $offset, 4 ); |
| | + |
| | + if( !ctype_xdigit( $lenHex ) ) return null; |
| | + |
| | $len = hexdec( $lenHex ); |
| | |
 |
| | |
| | $offset += 4; |
| | - $data = substr( $input, $offset, $len - 4 ); |
| | - $offset += $len - 4; |
| | + $dataLen = $len - 4; |
| | + |
| | + if( $offset + $dataLen > strlen( $input ) ) { |
| | + return null; |
| | + } |
| | + |
| | + $data = substr( $input, $offset, $dataLen ); |
| | + $offset += $dataLen; |
| | |
| | return $data; |