fix: out-of-bound memory acess sonarcloud warning (#2364)

This commit is contained in:
Charles Kerr 2021-12-29 21:48:50 -06:00 committed by GitHub
parent 23b7f02100
commit 26110d5c8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -129,6 +129,8 @@ void two_major_two_minor_formatter(char* buf, size_t buflen, std::string_view na
bool decodeShad0wClient(char* buf, size_t buflen, std::string_view in)
{
auto const* const buf_in = buf;
// Shad0w with his experimental BitTorrent implementation and BitTornado
// introduced peer ids that begin with a character which is``T`` in the
// case of BitTornado followed by up to five ascii characters for version
@ -199,7 +201,10 @@ bool decodeShad0wClient(char* buf, size_t buflen, std::string_view in)
std::rbegin(vals),
std::rend(vals),
[&buf, &buflen](int num) { std::tie(buf, buflen) = buf_append(buf, buflen, num, '.'); });
if (buf > buf_in)
{
buf[-1] = '\0'; // remove trailing '.'
}
return true;
}