merge bitcoin#23538: Remove strtol in torcontrol

This commit is contained in:
Kittywhiskers Van Gogh 2024-10-01 04:05:07 +00:00
parent 2318d9f996
commit 1f4e8a0cf9
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 10 additions and 8 deletions

View File

@ -21,16 +21,13 @@
#include <deque> #include <deque>
#include <functional> #include <functional>
#include <set> #include <set>
#include <stdlib.h>
#include <vector> #include <vector>
#include <boost/signals2/signal.hpp>
#include <event2/bufferevent.h>
#include <event2/buffer.h> #include <event2/buffer.h>
#include <event2/util.h> #include <event2/bufferevent.h>
#include <event2/event.h> #include <event2/event.h>
#include <event2/thread.h> #include <event2/thread.h>
#include <event2/util.h>
/** Default control port */ /** Default control port */
const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:9051"; const std::string DEFAULT_TOR_CONTROL = "127.0.0.1:9051";
@ -273,9 +270,15 @@ std::map<std::string,std::string> ParseTorReplyMapping(const std::string &s)
if (j == 3 && value[i] > '3') { if (j == 3 && value[i] > '3') {
j--; 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 // Account for automatic incrementing at loop end
i += j - 1; --i;
} else { } else {
escaped_value.push_back(value[i]); escaped_value.push_back(value[i]);
} }

View File

@ -47,7 +47,6 @@ KNOWN_VIOLATIONS=(
"src/test/dbwrapper_tests.cpp:.*snprintf" "src/test/dbwrapper_tests.cpp:.*snprintf"
"src/test/fuzz/locale.cpp" "src/test/fuzz/locale.cpp"
"src/test/fuzz/string.cpp" "src/test/fuzz/string.cpp"
"src/torcontrol.cpp:.*strtol"
"src/util/strencodings.cpp:.*strtoll" "src/util/strencodings.cpp:.*strtoll"
"src/util/system.cpp:.*fprintf" "src/util/system.cpp:.*fprintf"
) )