Skip to content

Commit 1cf8d0f

Browse files
committed
Make sure we have enough bytes before doing substr operations
1 parent 49acd4c commit 1cf8d0f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ThriftExtras/Transport/TSaslClientTransport.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,14 @@ private function saslRead_($statusByte = false) {
190190
}
191191

192192
private function getFromBuffer_($len) {
193-
$return = TStringFuncFactory::create()->substr( $this->readBuffer_, 0, $len );
194-
$this->readBuffer_ = TStringFuncFactory::create()->substr( $this->readBuffer_, $len );
193+
if ( TStringFuncFactory::create()->strlen( $this->readBuffer_ ) <= $len ) {
194+
$return = $this->readBuffer_;
195+
$this->readBuffer_ = '';
196+
} else {
197+
$return = TStringFuncFactory::create()->substr( $this->readBuffer_, 0, $len );
198+
$this->readBuffer_ = TStringFuncFactory::create()->substr( $this->readBuffer_, $len );
199+
}
195200

196201
return $return;
197202
}
198203
}
199-

0 commit comments

Comments
 (0)