From 85622befb8ded179c3c9a2ede42cfcfe0804b5da Mon Sep 17 00:00:00 2001 From: nmzik Date: Thu, 30 Jul 2026 00:48:08 +0200 Subject: [PATCH] Fix fabricated HTTP2 success (#129) @StefanosCosta Thanks! --- src/libs/libNet.cpp | 75 ++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/src/libs/libNet.cpp b/src/libs/libNet.cpp index 05407b3d2..30222265d 100644 --- a/src/libs/libNet.cpp +++ b/src/libs/libNet.cpp @@ -654,6 +654,8 @@ namespace LibHttp2 { LIB_VERSION("Http2", 1, "Http2", 1, 1); constexpr int HTTP2_ERROR_INVALID_ID = -2122641152; /* 0x817B1100 */ +constexpr int HTTP2_ERROR_BEFORE_SEND = -2122641307; /* 0x817B1065 */ +constexpr int HTTP2_ERROR_TIMEOUT = -2122641304; /* 0x817B1068 */ constexpr int HTTP2_ERROR_NULL_POINTER = -2122640859; /* 0x817B1225 */ struct Http2Options { @@ -694,14 +696,14 @@ struct Http2Request { std::string url; uint64_t content_length = 0; std::vector> headers; - bool sent = false; - int status_code = 204; - std::string response_headers = "HTTP/2 204 No Content\r\n\r\n"; - std::string response_body; - size_t read_offset = 0; - int async_result = 0; - int async_event = 0; - Http2Options options; + int send_result = HTTP2_ERROR_BEFORE_SEND; + int status_code = 0; + std::string response_headers; + std::string response_body; + size_t read_offset = 0; + int async_result = HTTP2_ERROR_BEFORE_SEND; + int async_event = 0; + Http2Options options; }; struct Http2AsyncResult { @@ -1114,9 +1116,9 @@ static int KYTY_SYSV_ABI Http2SendRequest(int req_id, const void* post_data, siz return HTTP2_ERROR_INVALID_ID; } - request->second.sent = true; + request->second.send_result = HTTP2_ERROR_TIMEOUT; - return 0; + return request->second.send_result; } static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data, size_t size, @@ -1136,8 +1138,8 @@ static int KYTY_SYSV_ABI Http2SendRequestAsync(int req_id, const void* post_data return HTTP2_ERROR_INVALID_ID; } - request->second.sent = true; - request->second.async_result = 0; + request->second.send_result = HTTP2_ERROR_TIMEOUT; + request->second.async_result = request->second.send_result; request->second.async_event = 0; return 0; @@ -1159,11 +1161,10 @@ static int KYTY_SYSV_ABI Http2WaitAsync(int req_id, Http2AsyncResult* result, ui return HTTP2_ERROR_INVALID_ID; } - request->second.sent = true; - *result = {}; - result->event_type = request->second.async_event; - result->req_id = req_id; - result->result = request->second.async_result; + *result = {}; + result->event_type = request->second.async_event; + result->req_id = req_id; + result->result = request->second.async_result; return 0; } @@ -1178,13 +1179,19 @@ static int KYTY_SYSV_ABI Http2GetStatusCode(int req_id, int* status_code) { return HTTP2_ERROR_NULL_POINTER; } + *status_code = 0; + auto request = g_http2_requests.find(req_id); if (request == g_http2_requests.end()) { return HTTP2_ERROR_INVALID_ID; } - *status_code = request->second.status_code; + const int send_result = request->second.send_result; + if (send_result != 0) { + return send_result; + } + *status_code = request->second.status_code; return 0; } @@ -1200,14 +1207,21 @@ static int KYTY_SYSV_ABI Http2GetResponseContentLength(int req_id, int* result, return HTTP2_ERROR_NULL_POINTER; } + *result = 0; + *content_length = 0; + auto request = g_http2_requests.find(req_id); if (request == g_http2_requests.end()) { return HTTP2_ERROR_INVALID_ID; } - *result = 0; // SCE_HTTP2_CONTENTLEN_EXIST - *content_length = request->second.response_body.size(); + const int send_result = request->second.send_result; + if (send_result != 0) { + *result = -1; + return send_result; + } + *content_length = request->second.response_body.size(); return 0; } @@ -1223,14 +1237,21 @@ static int KYTY_SYSV_ABI Http2GetAllResponseHeaders(int req_id, char** header, return HTTP2_ERROR_NULL_POINTER; } + *header = nullptr; + *header_size = 0; + auto request = g_http2_requests.find(req_id); if (request == g_http2_requests.end()) { return HTTP2_ERROR_INVALID_ID; } + const int send_result = request->second.send_result; + if (send_result != 0) { + return send_result; + } + *header = const_cast(request->second.response_headers.c_str()); *header_size = request->second.response_headers.size(); - return 0; } @@ -1250,6 +1271,11 @@ static int KYTY_SYSV_ABI Http2ReadData(int req_id, void* data, size_t size) { return HTTP2_ERROR_INVALID_ID; } + const int send_result = request->second.send_result; + if (send_result != 0) { + return send_result; + } + const auto& body = request->second.response_body; const auto remaining = request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0; @@ -1280,6 +1306,13 @@ static int KYTY_SYSV_ABI Http2ReadDataAsync(int req_id, void* data, size_t size, return HTTP2_ERROR_INVALID_ID; } + const int send_result = request->second.send_result; + if (send_result != 0) { + request->second.async_result = send_result; + request->second.async_event = 1; + return 0; + } + const auto& body = request->second.response_body; const auto remaining = request->second.read_offset < body.size() ? body.size() - request->second.read_offset : 0;