Reject out-of-range RPC values instead of narrowing them silently.

Guards choke group max, set-port and info-hash length; parsing now uses std::from_chars.
This commit is contained in:
xirvik
2026-09-19 01:03:55 +00:00
parent 05cdd03cd2
commit f79cb257d7
15 changed files with 424 additions and 17 deletions
+13
View File
@@ -1,12 +1,25 @@
#ifndef RTORRENT_UTILS_COMMAND_HELPERS_H
#define RTORRENT_UTILS_COMMAND_HELPERS_H
#include <cstdint>
#include <limits>
#include <string>
#include <torrent/exceptions.h>
#include "rpc/command.h"
#include "rpc/parse_commands.h"
#include "rpc/object_storage.h"
void initialize_commands();
inline uint16_t
checked_port_value(int64_t value, const char* label) {
if (value < 0 || value > std::numeric_limits<uint16_t>::max())
throw torrent::input_error(std::string("Invalid ") + label + " port number.");
return static_cast<uint16_t>(value);
}
//
// Aliases with CMD_* for the below
//