diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-08-18 01:25:53 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-17 20:25:53 +0100 |
commit | 8fe1612bdb6572fc60284190351ed4075d72402a (patch) | |
tree | 53e8e1020764d4526334e06372cf2beb8d899be2 /src/client | |
parent | 1e661a2fc6e31aa0c5be710dde274ec199ff3853 (diff) | |
download | rspamd-8fe1612bdb6572fc60284190351ed4075d72402a.tar.gz rspamd-8fe1612bdb6572fc60284190351ed4075d72402a.zip |
Fix issue with broken HTTP message to learn endpoints (#5106)
* [Fix] Check message before trying to dereference pointer
Issue: #5089
* [Minor] Fix stripping of the last characters
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/rspamc.cxx | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/client/rspamc.cxx b/src/client/rspamc.cxx index 1e0830493..1c67e4167 100644 --- a/src/client/rspamc.cxx +++ b/src/client/rspamc.cxx @@ -524,16 +524,13 @@ rspamc_password_callback(const char *option_name, else { /* Strip trailing spaces */ auto *map = (char *) locked_mmap.value().get_map(); - auto *end = map + locked_mmap.value().get_size() - 1; - - while (g_ascii_isspace(*end) && end > map) { - end--; - } - - end++; - value_view = std::string_view{map, static_cast<std::size_t>(end - map + 1)}; - processed_passwd.assign(std::begin(value_view), std::end(value_view)); - processed_passwd.push_back('\0'); + value_view = std::string_view{map, locked_mmap->get_size()}; + auto right = value_view.end() - 1; + for (; right > value_view.cbegin() && g_ascii_isspace(*right); --right) + ; + std::string_view str{value_view.begin(), static_cast<size_t>(right - value_view.begin()) + 1}; + processed_passwd.assign(std::begin(str), std::end(str)); + processed_passwd.push_back('\0'); /* Null-terminate for C part */ } } else { |