From 5f86c008e22ffca82d376a7618d49d26f7329c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Botond=20D=C3=A9nes?= Date: Tue, 7 Apr 2026 16:35:31 +0300 Subject: [PATCH] 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 816f2bf163e8b536767a700602d989e180f9e225) Closes scylladb/scylladb#29468 --- test/boost/types_test.cc | 14 ++++++++++++++ types/types.cc | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/test/boost/types_test.cc b/test/boost/types_test.cc index 05b3c85773..11f86e564f 100644 --- a/test/boost/types_test.cc +++ b/test/boost/types_test.cc @@ -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"})))); } diff --git a/types/types.cc b/types/types.cc index 5284d92a0e..cf319167a8 100644 --- a/types/types.cc +++ b/types/types.cc @@ -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();