Merge 'cql3: fix null handling in data_value formatting' from Dario Mirovic

`data_value::to_parsable_string()` crashes with a null pointer dereference when called on a `null` data_value. Return `"null"` instead.

Added tests after the fix. Manually checked that tests fail without the fix.

Fixes SCYLLADB-1350

This is a fix that prevents format crash. No known occurrence in production, but backport is desirable.

Closes scylladb/scylladb#29262

* github.com:scylladb/scylladb:
  test: boost: test null data value to_parsable_string
  cql3: fix null handling in data_value formatting

(cherry picked from commit 816f2bf163)

Closes scylladb/scylladb#29468
This commit is contained in:
Botond Dénes
2026-04-07 16:35:31 +03:00
parent dd8a6ab37f
commit 5f86c008e2
2 changed files with 18 additions and 0 deletions

View File

@@ -56,6 +56,20 @@ BOOST_AUTO_TEST_CASE(test_null_is_not_empty) {
BOOST_REQUIRE(empty != null);
}
BOOST_AUTO_TEST_CASE(test_null_data_value_to_parsable_string) {
auto null_utf8 = data_value::make_null(utf8_type);
BOOST_REQUIRE_EQUAL(null_utf8.to_parsable_string(), "null");
auto null_int = data_value::make_null(int32_type);
BOOST_REQUIRE_EQUAL(null_int.to_parsable_string(), "null");
auto null_list = data_value::make_null(list_type_impl::get_instance(int32_type, true));
BOOST_REQUIRE_EQUAL(null_list.to_parsable_string(), "null");
auto null_map = data_value::make_null(map_type_impl::get_instance(utf8_type, int32_type, true));
BOOST_REQUIRE_EQUAL(null_map.to_parsable_string(), "null");
}
BOOST_AUTO_TEST_CASE(test_bytes_type_string_conversions) {
BOOST_REQUIRE(bytes_type->equal(bytes_type->from_string("616263646566"), bytes_type->decompose(data_value(bytes{"abcdef"}))));
}

View File

@@ -3602,6 +3602,10 @@ data_value::data_value(empty_type_representation e) : data_value(make_new(empty_
}
sstring data_value::to_parsable_string() const {
if (is_null()) {
return "null";
}
// For some reason trying to do it using fmt::format refuses to compile
// auto to_parsable_str_transform = std::views::transform([](const data_value& dv) -> sstring {
// return dv.to_parsable_string();