MDEV-37504 MemorySanitizer: use-of-uninitialized-value myrocks::Rdb_key_def::pack_field

m_charset_codec is uninitalized when calling m_make_unpack_info_func.

In the cases where m_make_unpack_info_func is one of:
* Rdb_key_def::make_unpack_unknown_varchar
* Rdb_key_def::make_unpack_unknown
* Rdb_key_def::dummy_make_unpack_info

the m_charset_coded that forms the first argument to this function
is unused.

In these limited cases we initialize the m_charset_codec member
as the only use is to pass though to the m_make_unpack_info_func

Ultimately MemorySanitizer shouldn't error on this as all
of these 3 functions clearly have the attribute
__unused__ on their first argument where the m_charset_coded is
passed.
This commit is contained in:
Daniel Black 2025-08-29 10:33:19 +10:00
commit a0384c2f88

View file

@ -3380,6 +3380,11 @@ bool Rdb_field_packing::setup(const Rdb_key_def *const key_descr,
m_skip_func = Rdb_key_def::skip_variable_space_pad;
m_pack_func = Rdb_key_def::pack_with_varchar_space_pad;
m_make_unpack_info_func = Rdb_key_def::dummy_make_unpack_info;
#if __has_feature(memory_sanitizer)
// dummy_make_unpack_info doesn't use arguments but MSAN expects
// them to be initialized.
m_charset_codec = nullptr;
#endif
m_segment_size = get_segment_size_from_collation(cs);
m_max_image_len =
(max_image_len_before_chunks / (m_segment_size - 1) + 1) *
@ -3453,6 +3458,15 @@ bool Rdb_field_packing::setup(const Rdb_key_def *const key_descr,
: Rdb_key_def::make_unpack_unknown;
m_unpack_func = is_varchar ? Rdb_key_def::unpack_unknown_varchar
: Rdb_key_def::unpack_unknown;
#if __has_feature(memory_sanitizer)
// Rdb_key_def::make_unpack_info_unknown and
// Rdb_key_def::make_unpack_unknown_varchar when called
// via m_make_unpack_info_func do not make use of the m_charset_codec
// provided as an argument. MemorySanitizer doesn't make the logical
// there is no risk in m_charset_codec being uninitialized. Therefore we
// initialize to make MemorySanitizer satisified.
m_charset_codec = nullptr;
#endif
} else {
// Same as above: we don't know how to restore the value from its
// mem-comparable form.