Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion ixwebsocket/IXHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ namespace ix
if (headers.find("Content-Length") != headers.end())
{
int contentLength = 0;
#ifdef __cpp_exceptions
try
{
contentLength = std::stoi(headers["Content-Length"]);
Expand All @@ -142,7 +143,22 @@ namespace ix
return std::make_tuple(
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
}

#else
{
const char* p = headers["Content-Length"].c_str();
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()) {
return std::make_tuple(
false, "Error parsing HTTP Header 'Content-Length'", httpRequest);
}
contentLength = val;
}
#endif
if (contentLength < 0)
{
return std::make_tuple(
Expand Down