Skip to content

Commit df79253

Browse files
committed
Add extended argument tests into the image
1 parent 3dd71b8 commit df79253

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

collector/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ container/bin/collector: cmake-build/collector
3737
mkdir -p container/bin
3838
cp "$(COLLECTOR_BIN_DIR)/collector" container/bin/collector
3939
cp "$(COLLECTOR_BIN_DIR)/self-checks" container/bin/self-checks
40+
cp "$(COLLECTOR_BIN_DIR)/test/ProcessSignalFormatterTest" container/bin/ProcessSignalFormatterTest
4041

4142
.PHONY: collector
4243
collector: container/bin/collector txt-files

collector/container/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ COPY container/THIRD_PARTY_NOTICES/ /THIRD_PARTY_NOTICES/
2929
COPY kernel-modules /kernel-modules
3030
COPY container/bin/collector /usr/local/bin/
3131
COPY container/bin/self-checks /usr/local/bin/self-checks
32+
COPY container/bin/ProcessSignalFormatterTest /usr/local/bin/ProcessSignalFormatterTest
3233
COPY container/status-check.sh /usr/local/bin/status-check.sh
3334

3435
RUN echo "${MODULE_VERSION}" > /kernel-modules/MODULE_VERSION.txt && \

collector/test/ProcessSignalFormatterTest.cpp

+131
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,137 @@ TEST(ProcessSignalFormatterTest, Rox3377ProcessLineageWithNoVPidTest) {
628628
CollectorStats::Reset();
629629
}
630630

631+
TEST(ProcessSignalFormatterTest, EmptyArgument) {
632+
std::unique_ptr<sinsp> inspector(new sinsp());
633+
CollectorConfig config;
634+
635+
ProcessSignalFormatter processSignalFormatter(inspector.get(), config);
636+
637+
auto tinfo = inspector->build_threadinfo();
638+
tinfo->m_pid = 3;
639+
tinfo->m_tid = 3;
640+
tinfo->m_ptid = -1;
641+
tinfo->m_vpid = 0;
642+
tinfo->m_user.set_uid(42);
643+
tinfo->m_container_id = "";
644+
tinfo->m_exepath = "qwerty";
645+
646+
sinsp_evt* evt = new sinsp_evt();
647+
scap_evt* s_evt = new scap_evt();
648+
s_evt->type = PPME_SYSCALL_EXECVE_19_X;
649+
650+
// An empty argument
651+
tinfo->set_args("", 0);
652+
evt->set_tinfo(tinfo.get());
653+
evt->set_scap_evt(s_evt);
654+
655+
EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Empty argument failed";
656+
}
657+
658+
TEST(ProcessSignalFormatterTest, LargeArgumentWithoutNull) {
659+
std::unique_ptr<sinsp> inspector(new sinsp());
660+
CollectorConfig config;
661+
char* test;
662+
663+
ProcessSignalFormatter processSignalFormatter(inspector.get(), config);
664+
665+
auto tinfo = inspector->build_threadinfo();
666+
tinfo->m_pid = 3;
667+
tinfo->m_tid = 3;
668+
tinfo->m_ptid = -1;
669+
tinfo->m_vpid = 0;
670+
tinfo->m_user.set_uid(42);
671+
tinfo->m_container_id = "";
672+
tinfo->m_exepath = "qwerty";
673+
674+
sinsp_evt* evt = new sinsp_evt();
675+
scap_evt* s_evt = new scap_evt();
676+
s_evt->type = PPME_SYSCALL_EXECVE_19_X;
677+
678+
// A large argument without a null terminator
679+
test = (char*)malloc(8192);
680+
memset(test, 0xff, 8192);
681+
682+
tinfo->set_args(test, 8192);
683+
evt->set_tinfo(tinfo.get());
684+
evt->set_scap_evt(s_evt);
685+
686+
EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Large argument without a null terminator failed";
687+
}
688+
689+
TEST(ProcessSignalFormatterTest, SmallArgumentWithoutNull) {
690+
std::unique_ptr<sinsp> inspector(new sinsp());
691+
CollectorConfig config;
692+
char* test;
693+
694+
ProcessSignalFormatter processSignalFormatter(inspector.get(), config);
695+
696+
auto tinfo = inspector->build_threadinfo();
697+
tinfo->m_pid = 3;
698+
tinfo->m_tid = 3;
699+
tinfo->m_ptid = -1;
700+
tinfo->m_vpid = 0;
701+
tinfo->m_user.set_uid(42);
702+
tinfo->m_container_id = "";
703+
tinfo->m_exepath = "qwerty";
704+
705+
sinsp_evt* evt = new sinsp_evt();
706+
scap_evt* s_evt = new scap_evt();
707+
s_evt->type = PPME_SYSCALL_EXECVE_19_X;
708+
709+
// A small argument without a null terminator
710+
test = (char*)malloc(200);
711+
memset(test, 0xff, 200);
712+
713+
tinfo->set_args(test, 200);
714+
evt->set_tinfo(tinfo.get());
715+
evt->set_scap_evt(s_evt);
716+
717+
EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Small argument without a null terminator failed";
718+
}
719+
720+
TEST(ProcessSignalFormatterTest, InvalidUTF8) {
721+
std::unique_ptr<sinsp> inspector(new sinsp());
722+
CollectorConfig config;
723+
char* test;
724+
725+
ProcessSignalFormatter processSignalFormatter(inspector.get(), config);
726+
727+
auto tinfo = inspector->build_threadinfo();
728+
tinfo->m_pid = 3;
729+
tinfo->m_tid = 3;
730+
tinfo->m_ptid = -1;
731+
tinfo->m_vpid = 0;
732+
tinfo->m_user.set_uid(42);
733+
tinfo->m_container_id = "";
734+
tinfo->m_exepath = "qwerty";
735+
736+
sinsp_evt* evt = new sinsp_evt();
737+
scap_evt* s_evt = new scap_evt();
738+
s_evt->type = PPME_SYSCALL_EXECVE_19_X;
739+
740+
// An argument with invalid UTF-8 sequence
741+
test = (char*)malloc(200);
742+
memset(test, 0xff, 200);
743+
test[0] = 0xe2;
744+
test[1] = 0xcf;
745+
test[2] = 0xcf;
746+
test[3] = 0xff;
747+
test[4] = 0xff;
748+
test[5] = 0xff;
749+
test[6] = 0xff;
750+
test[7] = 0xff;
751+
test[8] = 0xff;
752+
test[9] = 0xff;
753+
test[10] = 0xff;
754+
755+
tinfo->set_args(test, 200);
756+
evt->set_tinfo(tinfo.get());
757+
evt->set_scap_evt(s_evt);
758+
759+
EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Invalid UTF-8 argument failed";
760+
}
761+
631762
} // namespace
632763

633764
} // namespace collector

0 commit comments

Comments
 (0)