Commit 4e7f7c2c authored by Gavin Brown's avatar Gavin Brown
Browse files

Patch from Nigel Kukard <nkukard@lbsd.net> which handles frame headers split over small buffers.

parent 48061715
...@@ -38,17 +38,18 @@ class Net_EPP_Protocol { ...@@ -38,17 +38,18 @@ class Net_EPP_Protocol {
* @return PEAR_Error|string either an error or a string * @return PEAR_Error|string either an error or a string
*/ */
static function getFrame($socket) { static function getFrame($socket) {
if (@feof($socket)) return new PEAR_Error('connection closed (socket is EOF)'); $hdr = '';
while (strlen($hdr) < 4) {
if (@feof($socket)) return new PEAR_Error('Connection closed (socket is EOF)');
if (($hdrstr = @fread($socket,4 - strlen($hdr))) !== false) {
$hdr .= $hdrstr;
$hdr = @fread($socket, 4); } else {
return new PEAR_ERROR('Error reading from socket:'.$php_errormsg);
if (empty($hdr) && feof($socket)) {
return new PEAR_Error('connection closed (no header received and socket is EOF)');
} elseif (false === $hdr) { }
return new PEAR_Error('Error reading from peer: '.$php_errormsg); }
} else {
$unpacked = unpack('N', $hdr); $unpacked = unpack('N', $hdr);
$length = $unpacked[1]; $length = $unpacked[1];
if ($length < 5) { if ($length < 5) {
...@@ -60,7 +61,7 @@ class Net_EPP_Protocol { ...@@ -60,7 +61,7 @@ class Net_EPP_Protocol {
// sometimes the socket can be buffered with a limit below the frame // sometimes the socket can be buffered with a limit below the frame
// length, so we continually read from the socket until we get the full frame: // length, so we continually read from the socket until we get the full frame:
$frame = ''; $frame = '';
while (strlen($frame) < $length) $frame .= fread($socket, ($length)); while (strlen($frame) < $length) $frame .= fread($socket, $length);
if (strlen($frame) > $length) { if (strlen($frame) > $length) {
return new PEAR_Error(sprintf("Frame length (%d bytes) doesn't match header (%d bytes)", strlen($frame), ($length))); return new PEAR_Error(sprintf("Frame length (%d bytes) doesn't match header (%d bytes)", strlen($frame), ($length)));
...@@ -71,7 +72,6 @@ class Net_EPP_Protocol { ...@@ -71,7 +72,6 @@ class Net_EPP_Protocol {
} }
} }
} }
}
/** /**
* send an EPP frame to the remote peer * send an EPP frame to the remote peer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment