mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-09 19:52:31 +00:00
ui: bound the input history size.
Only the lower end was checked, so a large value threw bad_alloc and exited.
This commit is contained in:
+4
-2
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <torrent/throttle.h>
|
||||
#include <torrent/torrent.h>
|
||||
@@ -354,8 +355,9 @@ Root::reset_input_history_attributes(ui::DownloadList::Input type) {
|
||||
|
||||
void
|
||||
Root::set_input_history_size(int size) {
|
||||
if (size < 1)
|
||||
throw torrent::input_error("Invalid input history size.");
|
||||
if (size < 1 || size > max_input_history_size)
|
||||
throw torrent::input_error("Input history size must be between 1 and " +
|
||||
std::to_string(max_input_history_size) + ".");
|
||||
|
||||
for (auto& [entry, category] : m_input_history) {
|
||||
// Reserve the latest input history entries if new size is smaller than original.
|
||||
|
||||
@@ -54,6 +54,11 @@ public:
|
||||
typedef std::vector<std::string> InputHistoryCategory;
|
||||
typedef std::map<int, InputHistoryCategory> InputHistory;
|
||||
|
||||
// Every category holds this many entries, and the whole history is written to
|
||||
// and read back from the session, so the useful range ends long before the
|
||||
// point where resizing it becomes a memory problem.
|
||||
static constexpr int max_input_history_size = 4096;
|
||||
|
||||
Root();
|
||||
|
||||
void init(Control* c);
|
||||
|
||||
Reference in New Issue
Block a user