diff --git a/collector/test/ProcessSignalFormatterTest.cpp b/collector/test/ProcessSignalFormatterTest.cpp index c95f91c9dc..d2a6548168 100644 --- a/collector/test/ProcessSignalFormatterTest.cpp +++ b/collector/test/ProcessSignalFormatterTest.cpp @@ -616,6 +616,54 @@ TEST(ProcessSignalFormatterTest, Rox3377ProcessLineageWithNoVPidTest) { CollectorStats::Reset(); } +TEST(ProcessSignalFormatterTest, EmptyArgument) { + std::unique_ptr 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