diff options
author | W. J. van der Laan <laanwj@protonmail.com> | 2021-11-25 11:39:44 +0100 |
---|---|---|
committer | W. J. van der Laan <laanwj@protonmail.com> | 2021-11-25 11:39:54 +0100 |
commit | 791dd1f41ed787516169a33a590ca42b53f8b8fb (patch) | |
tree | 5d19822753a85f818c504e889b86600d3bd230e8 /src | |
parent | 9facad0da65815211e166870c7c9fb24e9b921ac (diff) | |
parent | fa186eb7f45a9d420503f96ff3a5f753afb75dec (diff) | |
download | bitcoin-791dd1f41ed787516169a33a590ca42b53f8b8fb.tar.xz |
Merge bitcoin/bitcoin#23538: Remove strtol in torcontrol
fa186eb7f45a9d420503f96ff3a5f753afb75dec Remove strtol in torcontrol (MarcoFalke)
Pull request description:
The sequence of octal chars is fully validated before calling `strtol`, so it can be replaced by a simple loop. This removes the last "locale depended" `strtol` call. Also, removes some unused includes.
ACKs for top commit:
laanwj:
Code review and tested ACK fa186eb7f45a9d420503f96ff3a5f753afb75dec
Tree-SHA512: aafa4c68046e5ec48824c4f2c18e4920e5fe1d1fa03a8a297b2f40d0a1967cd0dad3554352519073a1620714e958ed5133cbc6b70bedcc508a423551d829f80e
Diffstat (limited to 'src')
-rw-r--r-- | src/torcontrol.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index 55618a5c57..776981b7f7 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -22,19 +22,17 @@ #include <deque> #include <functional> #include <set> -#include <stdlib.h> #include <vector> -#include <boost/signals2/signal.hpp> -#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/classification.hpp> #include <boost/algorithm/string/replace.hpp> +#include <boost/algorithm/string/split.hpp> -#include <event2/bufferevent.h> #include <event2/buffer.h> -#include <event2/util.h> +#include <event2/bufferevent.h> #include <event2/event.h> #include <event2/thread.h> +#include <event2/util.h> /** Default control port */ const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:9051"; @@ -277,9 +275,15 @@ std::map<std::string,std::string> ParseTorReplyMapping(const std::string &s) if (j == 3 && value[i] > '3') { j--; } - escaped_value.push_back(strtol(value.substr(i, j).c_str(), nullptr, 8)); + const auto end{i + j}; + uint8_t val{0}; + while (i < end) { + val *= 8; + val += value[i++] - '0'; + } + escaped_value.push_back(char(val)); // Account for automatic incrementing at loop end - i += j - 1; + --i; } else { escaped_value.push_back(value[i]); } |