aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authornocomer <nocomer@yandex-team.ru>2022-02-13 22:46:53 +0300
committernocomer <nocomer@yandex-team.ru>2022-02-13 22:46:53 +0300
commit3df7211d3e3691f8e33b0a1fb1764fe810d59302 (patch)
tree74a3ac92c59311ab7f6e2cbbe74ed74774ec9473 /util/string
parent426bb223c9ee6cc41c8e9c7cdfd2ef49f92ea5bf (diff)
downloadydb-3df7211d3e3691f8e33b0a1fb1764fe810d59302.tar.gz
BALANCER-3382: fix UB in AsciiEqualsIgnoreCase for empty TStringBufs
Under ubsan call to AsciiEqualsIgnoreCase with empty TStringBuf passed in arguments results in error arcadia/util/string/ascii.h:183:52: runtime error: null pointer passed as argument 1, which is declared to never be null due to nullptr being passed to strnicmp ref:1996fab2dbf1aaf0eb58ee694522ec0973971fd9
Diffstat (limited to 'util/string')
-rw-r--r--util/string/ascii.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/util/string/ascii.h b/util/string/ascii.h
index 10344384d3..d376af153a 100644
--- a/util/string/ascii.h
+++ b/util/string/ascii.h
@@ -180,7 +180,13 @@ static inline bool AsciiEqualsIgnoreCase(const char* s1, const char* s2) noexcep
* @return true iff @c s1 ans @c s2 are case-insensitively equal.
*/
static inline bool AsciiEqualsIgnoreCase(const TStringBuf s1, const TStringBuf s2) noexcept {
- return (s1.size() == s2.size()) && strnicmp(s1.data(), s2.data(), s1.size()) == 0;
+ if (s1.size() != s2.size()) {
+ return false;
+ }
+ if (s1.empty()) {
+ return true;
+ }
+ return strnicmp(s1.data(), s2.data(), s1.size()) == 0;
}
/**