Skip to content

Commit a0384c2

Browse files
committed
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.
1 parent da5cffe commit a0384c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

storage/rocksdb/rdb_datadic.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3380,6 +3380,11 @@ bool Rdb_field_packing::setup(const Rdb_key_def *const key_descr,
33803380
m_skip_func = Rdb_key_def::skip_variable_space_pad;
33813381
m_pack_func = Rdb_key_def::pack_with_varchar_space_pad;
33823382
m_make_unpack_info_func = Rdb_key_def::dummy_make_unpack_info;
3383+
#if __has_feature(memory_sanitizer)
3384+
// dummy_make_unpack_info doesn't use arguments but MSAN expects
3385+
// them to be initialized.
3386+
m_charset_codec = nullptr;
3387+
#endif
33833388
m_segment_size = get_segment_size_from_collation(cs);
33843389
m_max_image_len =
33853390
(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,
34533458
: Rdb_key_def::make_unpack_unknown;
34543459
m_unpack_func = is_varchar ? Rdb_key_def::unpack_unknown_varchar
34553460
: Rdb_key_def::unpack_unknown;
3461+
#if __has_feature(memory_sanitizer)
3462+
// Rdb_key_def::make_unpack_info_unknown and
3463+
// Rdb_key_def::make_unpack_unknown_varchar when called
3464+
// via m_make_unpack_info_func do not make use of the m_charset_codec
3465+
// provided as an argument. MemorySanitizer doesn't make the logical
3466+
// there is no risk in m_charset_codec being uninitialized. Therefore we
3467+
// initialize to make MemorySanitizer satisified.
3468+
m_charset_codec = nullptr;
3469+
#endif
34563470
} else {
34573471
// Same as above: we don't know how to restore the value from its
34583472
// mem-comparable form.

0 commit comments

Comments
 (0)