Compare commits

...

2 Commits

Author SHA1 Message Date
xirvik a075001a73 Catch every json exception when processing a JSONRPC request.
A number overflow escaped the two handlers and killed the process.
2026-08-12 18:22:17 +02:00
xirvik 781520fef8 Close the connection when an SCGI header does not fit the buffer.
A malformed header aborted the process from the SCGI thread.
2026-08-12 15:48:39 +02:00
2 changed files with 7 additions and 6 deletions
+2 -5
View File
@@ -258,11 +258,8 @@ JsonRpc::process(const char* in_buffer, uint32_t length, slot_write callback) {
return callback(response_str.c_str(), response_str.size()); return callback(response_str.c_str(), response_str.size());
} catch (json::parse_error& e) { } catch (json::exception& e) {
auto err_str = json_error(JSONRPC_PARSE_ERROR, e.what(), nullptr).dump(-1, ' ', false, json::error_handler_t::replace); // Exception strings may contain invalid UTF-8, hence the ::replace
return callback(err_str.c_str(), err_str.size());
} catch (json::type_error& e) {
// Type errors may be caused by invalid UTF-8 strings in exception strings, hence the ::replace
auto err_str = json_error(JSONRPC_PARSE_ERROR, e.what(), nullptr).dump(-1, ' ', false, json::error_handler_t::replace); auto err_str = json_error(JSONRPC_PARSE_ERROR, e.what(), nullptr).dump(-1, ' ', false, json::error_handler_t::replace);
return callback(err_str.c_str(), err_str.size()); return callback(err_str.c_str(), err_str.size());
} }
+5 -1
View File
@@ -94,8 +94,12 @@ SCgiTask::event_read() {
if (m_content_length == 0) if (m_content_length == 0)
read_length--; read_length--;
if (read_length <= 0) if (read_length <= 0) {
if (m_content_length == 0)
return close();
throw torrent::internal_error("SCgiTask::event_read() no space in buffer for event_read."); throw torrent::internal_error("SCgiTask::event_read() no space in buffer for event_read.");
}
int bytes = ::recv(file_descriptor(), m_buffer.data() + m_position, read_length, 0); int bytes = ::recv(file_descriptor(), m_buffer.data() + m_position, read_length, 0);