Skip to content

Commit

Permalink
http: fixc crash when parsing headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeefo committed Jan 28, 2025
1 parent 2a521dd commit 11dc7fe
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions crlib/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# include <netinet/in.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <sys/uio.h>
# include <sys/uio.h>
# include <arpa/inet.h>
# include <unistd.h>
# include <errno.h>
Expand Down Expand Up @@ -166,8 +166,7 @@ class Socket final : public NonCopyable {
uint32_t timeout_;

public:
Socket () : socket_ (kInvalidSocket), timeout_ (2)
{ }
Socket () : socket_ (kInvalidSocket), timeout_ (2) {}

~Socket () {
disconnect ();
Expand All @@ -194,7 +193,7 @@ class Socket final : public NonCopyable {
return false;
}

auto getTimeouts = [&]() -> Twin <char *, int32_t> {
auto getTimeouts = [&] () -> Twin <char *, int32_t> {
#if defined (CR_WINDOWS)
DWORD tv = timeout_ * 1000;
#else
Expand Down Expand Up @@ -227,7 +226,7 @@ class Socket final : public NonCopyable {
if (socket_ != kInvalidSocket) {
closesocket (socket_);
}
#else
#else
if (socket_ != kInvalidSocket)
close (socket_);
#endif
Expand Down Expand Up @@ -318,8 +317,8 @@ class HttpClient final : public Singleton <HttpClient> {
}
++pos;
}
String response { reinterpret_cast <const char *> (buffer) };
size_t responseCodeStart = response.find ("HTTP/1.1");
String response { reinterpret_cast <const char *> (buffer), static_cast <size_t> (chunkSize_) };
const size_t responseCodeStart = response.find ("HTTP/1.1");

if (responseCodeStart != String::InvalidIndex) {
String respCode = response.substr (responseCodeStart + cr::bufsize ("HTTP 1/1 "), 3);
Expand All @@ -331,7 +330,7 @@ class HttpClient final : public Singleton <HttpClient> {
}

public:
void startup (StringRef hostCheck = "", StringRef errMessageIfHostDown = "", uint32_t timeout = DefaultSocketTimeout) {
void startup (StringRef hostCheck = "", StringRef errMessageIfHostDown = "", uint32_t timeout = DefaultSocketTimeout) {
detail::SocketInit::start ();

initialized_ = true;
Expand All @@ -354,7 +353,7 @@ class HttpClient final : public Singleton <HttpClient> {
else {
hasConnection = true;
}
}};
} };
}
else {
hasConnection = true;
Expand Down

0 comments on commit 11dc7fe

Please sign in to comment.