mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-04 21:29:21 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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 \
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user