Give network.xmlrpc.size_limit.set a floor

A limit below any valid request rejects the request that would raise it again.
This commit is contained in:
xirvik
2026-09-19 02:23:52 +00:00
committed by Jari Sundell
parent 4e7129c71c
commit 8ee3b984dd
5 changed files with 48 additions and 1 deletions
+3
View File
@@ -172,6 +172,9 @@ RpcManager::set_size_limit(uint64_t size) {
if (size > SCgiTask::max_content_size)
throw torrent::input_error("XMLRPC size limit cannot exceed the SCGI content size limit.");
if (size < min_size_limit)
throw torrent::input_error("XMLRPC size limit is too small to hold a request.");
m_xmlrpc.set_size_limit(size);
}
+4
View File
@@ -53,6 +53,10 @@ public:
enum RPCType { XML,
JSON };
// A limit below the shortest useful request rejects every request, the one
// that would raise it again included.
static constexpr uint64_t min_size_limit = 1024;
RpcManager() = default;
~RpcManager() = default;
+3 -1
View File
@@ -52,7 +52,9 @@ rtorrent_Test_Rpc_SOURCES = $(rtorrent_Test_Common) \
rpc/test_object_storage.cc \
rpc/test_object_storage.h \
rpc/test_parse_options.cc \
rpc/test_parse_options.h
rpc/test_parse_options.h \
rpc/test_rpc_manager.cc \
rpc/test_rpc_manager.h
rtorrent_Test_Src_SOURCES = $(rtorrent_Test_Common) \
src/test_command_dynamic.cc \
+21
View File
@@ -0,0 +1,21 @@
#include "config.h"
#include "test/rpc/test_rpc_manager.h"
#include <torrent/exceptions.h>
#include "rpc/scgi_task.h"
CPPUNIT_TEST_SUITE_REGISTRATION(TestRpcManager);
// A size limit too small to hold any request rejects every request, including
// the one that would put it back, so it can only be undone by a restart.
void
TestRpcManager::test_size_limit_bounds() {
CPPUNIT_ASSERT_THROW(m_rpc_manager.set_size_limit(0), torrent::input_error);
CPPUNIT_ASSERT_THROW(m_rpc_manager.set_size_limit(rpc::RpcManager::min_size_limit - 1), torrent::input_error);
CPPUNIT_ASSERT_THROW(m_rpc_manager.set_size_limit(rpc::SCgiTask::max_content_size + 1), torrent::input_error);
CPPUNIT_ASSERT_NO_THROW(m_rpc_manager.set_size_limit(rpc::RpcManager::min_size_limit));
CPPUNIT_ASSERT_NO_THROW(m_rpc_manager.set_size_limit(rpc::SCgiTask::max_content_size));
}
+17
View File
@@ -0,0 +1,17 @@
#include "test/helpers/test_fixture.h"
#include "rpc/rpc_manager.h"
class TestRpcManager : public test_fixture {
CPPUNIT_TEST_SUITE(TestRpcManager);
CPPUNIT_TEST(test_size_limit_bounds);
CPPUNIT_TEST_SUITE_END();
public:
void test_size_limit_bounds();
private:
rpc::RpcManager m_rpc_manager;
};