From 412f5c2d077e40a77ae2f3bb4ac37cb63d2354f0 Mon Sep 17 00:00:00 2001 From: Chris Boden Date: Thu, 14 Jun 2012 10:54:26 -0400 Subject: [PATCH] [WebSocket] Re-scoped variable Protecting Frame::$data to prevent overflow error Correct frame contents is fetched from ::getContents() --- Version/RFC6455.php | 2 +- Version/RFC6455/Connection.php | 13 ++++--------- Version/RFC6455/Frame.php | 10 +++++++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Version/RFC6455.php b/Version/RFC6455.php index 29673ea..0d04513 100644 --- a/Version/RFC6455.php +++ b/Version/RFC6455.php @@ -177,7 +177,7 @@ class RFC6455 implements VersionInterface { * @return string */ public function frame($message, $mask = true) { - return $this->newFrame($message)->data; + return $this->newFrame($message)->getContents(); } /** diff --git a/Version/RFC6455/Connection.php b/Version/RFC6455/Connection.php index ee746fc..badd488 100644 --- a/Version/RFC6455/Connection.php +++ b/Version/RFC6455/Connection.php @@ -14,23 +14,18 @@ class Connection extends AbstractConnectionDecorator { } public function send($msg) { - if ($msg instanceof FrameInterface) { - $data = $msg->data; - } else { - $frame = new Frame($msg); - $data = $frame->data; + if (!($msg instanceof FrameInterface)) { + $msg = new Frame($msg); } - $this->getConnection()->send($data); + $this->getConnection()->send($msg->getContents()); } /** * {@inheritdoc} */ public function close($code = 1000) { - $frame = new Frame($code, true, Frame::OP_CLOSE); - - $this->send($frame->data); + $this->send(new Frame($code, true, Frame::OP_CLOSE)); $this->getConnection()->close(); } diff --git a/Version/RFC6455/Frame.php b/Version/RFC6455/Frame.php index 126ad4c..12fde14 100644 --- a/Version/RFC6455/Frame.php +++ b/Version/RFC6455/Frame.php @@ -29,7 +29,7 @@ class Frame implements FrameInterface { * The contents of the frame * @var string */ - public $data = ''; + protected $data = ''; /** * Number of bytes received from the frame @@ -367,6 +367,14 @@ class Frame implements FrameInterface { return $payload; } + /** + * Get the raw contents of the frame + * @todo This is untested, make sure the substr is right - trying to return the frame w/o the overflow + */ + public function getContents() { + return substr($this->data, 0, $this->getPayloadStartingByte() + $this->getPayloadLength()); + } + /** * Sometimes clients will concatinate more than one frame over the wire * This method will take the extra bytes off the end and return them