mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add safe_cast (RIPD-1702):
This change ensures that no overflow can occur when casting between enums and integral types.
This commit is contained in:
committed by
Nik Bougalis
parent
494724578a
commit
148bbf4e8f
@@ -20,6 +20,7 @@
|
||||
#ifndef RIPPLE_SERVER_BASEWSPEER_H_INCLUDED
|
||||
#define RIPPLE_SERVER_BASEWSPEER_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <ripple/server/impl/BasePeer.h>
|
||||
#include <ripple/protocol/BuildInfo.h>
|
||||
#include <ripple/beast/utility/rngfill.h>
|
||||
@@ -214,8 +215,9 @@ send(std::shared_ptr<WSMsg> w)
|
||||
{
|
||||
JLOG(this->j_.info()) <<
|
||||
"closing slow client";
|
||||
cr_.code = static_cast<boost::beast::websocket::close_code>(4000);
|
||||
cr_.reason = "Client is too slow.";
|
||||
cr_.code = safe_cast<decltype(cr_.code)>
|
||||
(boost::beast::websocket::close_code::policy_error);
|
||||
cr_.reason = "Policy error: client is too slow.";
|
||||
wq_.erase(std::next(wq_.begin()), wq_.end());
|
||||
close();
|
||||
return;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/safe_cast.h>
|
||||
#include <ripple/server/Port.h>
|
||||
#include <ripple/beast/rfc2616.h>
|
||||
#include <ripple/beast/core/LexicalCast.h>
|
||||
@@ -192,7 +193,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log)
|
||||
{
|
||||
try
|
||||
{
|
||||
port.limit = static_cast<int> (
|
||||
port.limit = safe_cast<int> (
|
||||
beast::lexicalCastThrow<std::uint16_t>(lim));
|
||||
}
|
||||
catch (std::exception const&)
|
||||
|
||||
Reference in New Issue
Block a user