From: Daniel Rudolf Date: Wed, 27 Feb 2013 11:38:27 +0000 (+0100) Subject: HTTPRequest: Validate length before status code X-Git-Tag: 2.0.0_Beta_1~453^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a0eb8370c04cf22a4f75867ef6db8a83a1b487a3;p=GitHub%2FWoltLab%2FWCF.git HTTPRequest: Validate length before status code --- diff --git a/wcfsetup/install/files/lib/util/HTTPRequest.class.php b/wcfsetup/install/files/lib/util/HTTPRequest.class.php index 52c7c16e6a..54709f554e 100644 --- a/wcfsetup/install/files/lib/util/HTTPRequest.class.php +++ b/wcfsetup/install/files/lib/util/HTTPRequest.class.php @@ -190,23 +190,32 @@ final class HTTPRequest { } $this->replyHeaders = $headers; + // get status code $statusLine = reset($this->replyHeaders); $regex = new Regex('^HTTP/1.(?:0|1) (\d{3})'); if (!$regex->match($statusLine)) throw new SystemException("Unexpected status '".$statusLine."'"); $matches = $regex->getMatches(); $this->statusCode = $matches[1]; + // validate length + if (isset($this->replyHeaders['Content-Length'])) { + if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) { + throw new SystemException('Body length does not match length given in header'); + } + } + + // validate status code switch ($this->statusCode) { case '301': case '302': case '303': case '307': // redirect - if ($this->options['maxDepth'] <= 0) throw new SystemException("Got redirect status '".$statusCode."', but recursion level is exhausted"); + if ($this->options['maxDepth'] <= 0) throw new SystemException("Got redirect status '".$this->statusCode."', but recursion level is exhausted"); $newRequest = clone $this; $newRequest->options['maxDepth']--; - if ($statusCode != '307') { + if ($this->statusCode != '307') { $newRequest->options['method'] = 'GET'; $newRequest->postParameters = array(); $newRequest->addHeader('Content-length', ''); @@ -235,13 +244,6 @@ final class HTTPRequest { throw new SystemException("Got status '".$this->statusCode."' and I don't know how to handle it"); break; } - - // validate length - if (isset($this->replyHeaders['Content-Length'])) { - if (strlen($this->replyBody) != $this->replyHeaders['Content-Length']) { - throw new SystemException('Body length does not match length given in header'); - } - } } /**