Skip to content

Commit

Permalink
fixed crash-issue if 'name' or 'type' wasn't specified on a member, f…
Browse files Browse the repository at this point in the history
…ound by coverity, issue #84
  • Loading branch information
wc-duck committed Jul 24, 2018
1 parent f599a55 commit fbbf910
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/dl_typelib_read_txt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ static void dl_context_load_txt_type_library_read_member( dl_ctx_t ctx, dl_txt_r

} while( dl_txt_try_eat_char( read_state, ',') );

if(type.str == 0x0)
dl_txt_read_failed( ctx, read_state, DL_ERROR_MALFORMED_DATA, "member in type is missing 'type'-field");
if(name.str == 0x0)
dl_txt_read_failed( ctx, read_state, DL_ERROR_MALFORMED_DATA, "member in type is missing 'name'-field");

dl_member_desc* member = dl_alloc_member( ctx );
member->name = dl_alloc_string( ctx, &name );
dl_parse_type( ctx, &type, member, read_state );
Expand Down
23 changes: 22 additions & 1 deletion tests/dl_tests_typelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void typelibtxt_expect_error( dl_ctx_t ctx, dl_error_t expect, const char
EXPECT_DL_ERR_EQ( expect, dl_context_load_txt_type_library( ctx, libstr, strlen(libstr) ) );
}

TEST_F( DLTypeLibTxt, missing_type )
TEST_F( DLTypeLibTxt, member_missing_type )
{
typelibtxt_expect_error( ctx, DL_ERROR_TYPE_NOT_FOUND, STRINGIFY({
"module" : "small",
Expand All @@ -106,6 +106,27 @@ TEST_F( DLTypeLibTxt, missing_type )
}));
}

TEST_F( DLTypeLibTxt, member_missing_type_2 )
{
typelibtxt_expect_error( ctx, DL_ERROR_MALFORMED_DATA, STRINGIFY({
"module" : "small",
"types" : {
"single_int" : { "members" : [ { "name" : "member" } ] }
}
}));
}

TEST_F( DLTypeLibTxt, member_missing_name )
{
typelibtxt_expect_error( ctx, DL_ERROR_MALFORMED_DATA, STRINGIFY({
"module" : "small",
"types" : {
"single_int" : { "members" : [ { "type" : "uint32" } ] }
}
}));
}


TEST_F( DLTypeLibTxt, missing_comma )
{
const char single_member_typelib[] = STRINGIFY({
Expand Down

0 comments on commit fbbf910

Please sign in to comment.