From: James Turner Date: Tue, 7 Jan 2014 14:06:51 +0000 (+0000) Subject: HTTP: tweak for malformed header handling. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=1bd9a440e8e2968769f8c34703ce9965f5d16ca4;p=simgear.git HTTP: tweak for malformed header handling. --- diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index b7e19917..ecc63f84 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -65,6 +65,12 @@ class Connection; typedef std::multimap ConnectionDict; typedef std::list RequestList; +static bool isFailureStatus(int httpStatus) +{ + int majorCode = httpStatus / 100; + return (majorCode != 2); +} + class Client::ClientPrivate { public: @@ -214,8 +220,12 @@ public: assert(state == STATE_WAITING_FOR_RESPONSE); activeRequest = sentRequests.front(); - - activeRequest->responseStart(buffer); + activeRequest->responseStart(buffer); + if (isFailureStatus(activeRequest->responseCode())) { + handleError(EIO); + return; + } + state = STATE_GETTING_HEADERS; buffer.clear(); if (activeRequest->responseCode() == 204) { diff --git a/simgear/io/HTTPRequest.cxx b/simgear/io/HTTPRequest.cxx index e3980ca1..d51d9790 100644 --- a/simgear/io/HTTPRequest.cxx +++ b/simgear/io/HTTPRequest.cxx @@ -115,7 +115,6 @@ void Request::responseStart(const std::string& r) const int maxSplit = 2; // HTTP/1.1 nnn reason-string string_list parts = strutils::split(r, NULL, maxSplit); if (parts.size() != 3) { - SG_LOG(SG_IO, SG_WARN, "HTTP::Request: malformed response start:" << r); setFailure(400, "malformed HTTP response header"); return; }