Skip to content

Commit 51c10bb

Browse files
Refs #22202. Fix null-dereference error
Signed-off-by: Juan Lopez Fernandez <juanlopez@eprosima.com>
1 parent f7f40ac commit 51c10bb

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/cpp/fastdds/xtypes/serializers/json/dynamic_data_json.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ ReturnCode_t json_serialize_enum_member(
582582
enum_type = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_desc->type())->resolve_alias_enclosed_type();
583583
}
584584

585+
if (nullptr == enum_type)
586+
{
587+
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
588+
"Error encountered while serializing TK_ENUM member to JSON: null enum type.");
589+
return RETCODE_BAD_PARAMETER;
590+
}
591+
585592
// Get value depending on the enclosing type
586593
assert(enum_type->get_kind() == TK_ENUM);
587594
TypeKind enclosing_kind = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index().at(

src/cpp/fastdds/xtypes/serializers/json/json_dynamic_data.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,13 @@ ReturnCode_t json_deserialize_enum_member(
677677
enum_type = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_desc->type())->resolve_alias_enclosed_type();
678678
}
679679

680+
if (nullptr == enum_type)
681+
{
682+
EPROSIMA_LOG_ERROR(XTYPES_UTILS,
683+
"Error encountered while deserializing TK_ENUM member from JSON: null enum type.");
684+
return RETCODE_BAD_PARAMETER;
685+
}
686+
680687
// Get enclosing type kind to parse the value accordingly, and later user the appropriate setter
681688
assert(enum_type->get_kind() == TK_ENUM);
682689
TypeKind enclosing_kind = traits<DynamicType>::narrow<DynamicTypeImpl>(enum_type->get_all_members_by_index().at(

0 commit comments

Comments
 (0)