Skip to content

Commit

Permalink
Invalid UTF-8 test
Browse files Browse the repository at this point in the history
Add test for invalid UTF-8 sequence in process signal
  • Loading branch information
erthalion committed Sep 5, 2024
1 parent 4ace9a7 commit 649d4a4
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions collector/test/ProcessSignalFormatterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,54 @@ TEST(ProcessSignalFormatterTest, Rox3377ProcessLineageWithNoVPidTest) {
CollectorStats::Reset();
}

TEST(ProcessSignalFormatterTest, EmptyArgument) {
std::unique_ptr<sinsp> inspector(new sinsp());

ProcessSignalFormatter processSignalFormatter(inspector.get());

auto tinfo = inspector->build_threadinfo();
tinfo->m_pid = 3;
tinfo->m_tid = 3;
tinfo->m_ptid = -1;
tinfo->m_vpid = 0;
tinfo->m_user.set_uid(42);
tinfo->m_container_id = "";
tinfo->m_exepath = "qwerty";

char* test = (char*)malloc(8192);
// Clobber the string
memset(test, 0xff, 8192);
// Setup invalid UTF-8 sequence
test[0] = 0xe2;
test[1] = 0xcf;
test[2] = 0xcf;
test[3] = 0xff;
test[4] = 0xff;
test[5] = 0xff;
test[6] = 0xff;
test[7] = 0xff;
test[8] = 0xff;
test[9] = 0xff;
test[10] = 0xff;

// Take only a subset without the null terminator
tinfo->set_args(test, 8192);

sinsp_evt* evt = new sinsp_evt();
scap_evt* s_evt = new scap_evt();

s_evt->type = PPME_SYSCALL_EXECVE_19_X;
evt->set_tinfo(tinfo.get());
evt->set_scap_evt(s_evt);

const auto* signal_msg = processSignalFormatter.ToProtoMessage(evt);
void* target = (void*)malloc(9000);
google::protobuf::uint8* ptr = (google::protobuf::uint8*)malloc(9000);
google::protobuf::io::EpsCopyOutputStream* stream = new google::protobuf::io::EpsCopyOutputStream(target, 9000, 1);

signal_msg->_InternalSerialize(ptr, stream);
}

} // namespace

} // namespace collector

0 comments on commit 649d4a4

Please sign in to comment.