In this patch we replace every single use of SCYLLA_ASSERT() in the cql3/ directory by throwing_assert(). The problem with SCYLLA_ASSERT() is that when it fails, it crashes Scylla. This is almost always a bad idea (see #7871 discussing why), but it's even riskier in front-end code like cql3/: In front-end code, there is a risk that due to a bug in our code, a specific user request can cause Scylla to crash. A malicious user can send this query to all nodes and crash the entire cluster. When the user is not malicious, it causes a small problem (a failing request) to become a much worse crash - and worse, the user has no idea which request is causing this crash and the crash will repeat if the same request is tried again. All of this is solved by using the new throwing_assert(), which is the same as SCYLLA_ASSERT() but throws an exception (using on_internal_error()) instead of crashing. The exception will prevent the code path with the invalid assumption from continuing, but will result in only the current user request being aborted, with a clear error message reporting the internal server error due to an assertion failure. I reviewed all the changes that I did in this patch to check that (to the best of my understanding) none of the assertions in cql3/ involve the sort of serious corruption that might require crashing the Scylla node entirely. throwing_assert() also improves logging of assertion failures compared to the original SCYLLA_ASSERT() - SCYLLA_ASSERT() printed a message to stderr which in many installations is lost, whereas throwing_assert() uses Scylla's standard logger, and also includes a backtrace in the log message. Fixes #13970 (Exorcise assertions from CQL code paths) Refs #7871 (Exorcise assertions from Scylla) Signed-off-by: Nadav Har'El <nyh@scylladb.com>
47 lines
937 B
C++
47 lines
937 B
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*
|
|
* Modified by ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: (LicenseRef-ScyllaDB-Source-Available-1.0 and Apache-2.0)
|
|
*/
|
|
|
|
#include "utils/assert.hh"
|
|
#include "cql3/keyspace_element_name.hh"
|
|
|
|
namespace cql3 {
|
|
|
|
void keyspace_element_name::set_keyspace(std::string_view ks, bool keep_case)
|
|
{
|
|
_ks_name = to_internal_name(ks, keep_case);
|
|
}
|
|
|
|
bool keyspace_element_name::has_keyspace() const
|
|
{
|
|
return bool(_ks_name);
|
|
}
|
|
|
|
const sstring& keyspace_element_name::get_keyspace() const
|
|
{
|
|
throwing_assert(_ks_name);
|
|
return *_ks_name;
|
|
}
|
|
|
|
sstring keyspace_element_name::to_internal_name(std::string_view view, bool keep_case)
|
|
{
|
|
sstring name(view);
|
|
if (!keep_case) {
|
|
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
|
}
|
|
return name;
|
|
}
|
|
|
|
sstring keyspace_element_name::to_string() const
|
|
{
|
|
return has_keyspace() ? (get_keyspace() + ".") : "";
|
|
}
|
|
|
|
}
|