Skip to content

Commit

Permalink
Fixed a mildly annoying compliler warning by making this a static cas…
Browse files Browse the repository at this point in the history
…t instead of an implicit one. (#534)

I also rearranged some of the checks to add better error messages to the 'Content-Length' header check overall.
  • Loading branch information
Rodrick136 authored Dec 7, 2024
1 parent 0424295 commit fb5a1f0
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ixwebsocket/IXHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,27 @@ namespace ix
int contentLength = 0;
{
const char* p = headers["Content-Length"].c_str();
char* p_end{};
char* p_end {};
errno = 0;
long val = std::strtol(p, &p_end, 10);
if (p_end == p // invalid argument
|| errno == ERANGE // out of range
|| val < std::numeric_limits<int>::min()
|| val > std::numeric_limits<int>::max()) {
if (p_end == p // invalid argument
|| errno == ERANGE // out of range
)
{
return std::make_tuple(
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
}
contentLength = val;
if (val > std::numeric_limits<int>::max())
{
return std::make_tuple(
false, "Error: 'Content-Length' value was above max", httpRequest);
}
if (val < std::numeric_limits<int>::min())
{
return std::make_tuple(
false, "Error: 'Content-Length' value was below min", httpRequest);
}
contentLength = static_cast<int>(val);
}
if (contentLength < 0)
{
Expand Down

0 comments on commit fb5a1f0

Please sign in to comment.