diff --git a/userspace/libsinsp/sinsp_filtercheck.cpp b/userspace/libsinsp/sinsp_filtercheck.cpp index d4f9b6bcf1..f263b84b9c 100644 --- a/userspace/libsinsp/sinsp_filtercheck.cpp +++ b/userspace/libsinsp/sinsp_filtercheck.cpp @@ -213,7 +213,7 @@ bool flt_compare_string(cmpop op, char* operand1, char* operand2) case CO_BSTARTSWITH: throw sinsp_exception("'bstartswith' not supported for string filters"); case CO_ENDSWITH: - return (sinsp_utils::endswith(operand1, operand2)); + return (sinsp_utils::endswith(operand1, operand2, strlen(operand1), strlen(operand2))); case CO_GLOB: return sinsp_utils::glob_match(operand2, operand1); case CO_IGLOB: diff --git a/userspace/libsinsp/utils.cpp b/userspace/libsinsp/utils.cpp index 42a6da6d12..68c147b2b0 100644 --- a/userspace/libsinsp/utils.cpp +++ b/userspace/libsinsp/utils.cpp @@ -1432,26 +1432,6 @@ std::string replace(const std::string& str, const std::string& search, const std return s; } - -bool sinsp_utils::endswith(const std::string& str, const std::string& ending) -{ - if (ending.size() <= str.size()) - { - return (0 == str.compare(str.length() - ending.length(), ending.length(), ending)); - } - return false; -} - - -bool sinsp_utils::endswith(const char *str, const char *ending, uint32_t lstr, uint32_t lend) -{ - if (lstr >= lend) - { - return (0 == memcmp(ending, str + (lstr - lend), lend)); - } - return 0; -} - bool sinsp_utils::startswith(const std::string& s, const std::string& prefix) { if(prefix.empty()) diff --git a/userspace/libsinsp/utils.h b/userspace/libsinsp/utils.h index 68e087f34b..895e8d1170 100644 --- a/userspace/libsinsp/utils.h +++ b/userspace/libsinsp/utils.h @@ -26,6 +26,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -80,8 +81,23 @@ class sinsp_utils // // Check if string ends with another // - static bool endswith(const std::string& str, const std::string& ending); - static bool endswith(const char *str, const char *ending, uint32_t lstr, uint32_t lend); + static inline bool endswith(const std::string& str, const std::string& ending) + { + if (ending.size() <= str.size()) + { + return (0 == str.compare(str.length() - ending.length(), ending.length(), ending)); + } + return false; + } + + static inline bool endswith(const char *str, const char *ending, uint32_t lstr, uint32_t lend) + { + if (lstr >= lend) + { + return (0 == memcmp(ending, str + (lstr - lend), lend)); + } + return 0; + } // // Check if string starts with another