Skip to content

Commit

Permalink
fix(libsinsp/test): remove illegal threat manager memory access in pl…
Browse files Browse the repository at this point in the history
…ugin tests

Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Jan 24, 2025
1 parent 4bebaed commit b301787
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 33 deletions.
69 changes: 39 additions & 30 deletions userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand All @@ -890,14 +898,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {
ASSERT_NE(dfield, subtable->dynamic_fields()->fields().end());
auto dfieldacc = dfield->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -918,7 +921,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -928,7 +931,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down Expand Up @@ -960,9 +963,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand All @@ -985,14 +996,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {
ASSERT_EQ(dfield->second.info(), libsinsp::state::typeinfo::of<std::string>());
auto dfieldacc = dfield->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1010,7 +1016,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1020,7 +1026,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down Expand Up @@ -1053,9 +1059,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand Down Expand Up @@ -1087,14 +1101,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {
ASSERT_EQ(dfield_second->second.info(), libsinsp::state::typeinfo::of<std::string>());
auto dfield_second_acc = dfield_second->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1114,7 +1123,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1124,7 +1133,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/plugins/syscall_subtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,

ss_plugin_table_t* fdtable = nullptr;

key.s64 = 0;
key.s64 = ev->evt->tid;
entry = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!entry) {
ps->lasterr = "can't get table entry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
ss_plugin_state_data out;
ss_plugin_state_data data;

key.s64 = 0;
key.s64 = ev->evt->tid;
ss_plugin_table_entry_t* tinfo = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!tinfo) {
ps->lasterr = "can't get table entry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
ss_plugin_state_data out;
ss_plugin_state_data data;

key.s64 = 0;
key.s64 = ev->evt->tid;
ss_plugin_table_entry_t* tinfo = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!tinfo) {
ps->lasterr = "can't get table entry";
Expand Down

0 comments on commit b301787

Please sign in to comment.