Skip to content

Commit

Permalink
Add extended argument tests into the image
Browse files Browse the repository at this point in the history
  • Loading branch information
erthalion committed Sep 27, 2024
1 parent 3dd71b8 commit df79253
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions collector/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ container/bin/collector: cmake-build/collector
mkdir -p container/bin
cp "$(COLLECTOR_BIN_DIR)/collector" container/bin/collector
cp "$(COLLECTOR_BIN_DIR)/self-checks" container/bin/self-checks
cp "$(COLLECTOR_BIN_DIR)/test/ProcessSignalFormatterTest" container/bin/ProcessSignalFormatterTest

.PHONY: collector
collector: container/bin/collector txt-files
Expand Down
1 change: 1 addition & 0 deletions collector/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ COPY container/THIRD_PARTY_NOTICES/ /THIRD_PARTY_NOTICES/
COPY kernel-modules /kernel-modules
COPY container/bin/collector /usr/local/bin/
COPY container/bin/self-checks /usr/local/bin/self-checks
COPY container/bin/ProcessSignalFormatterTest /usr/local/bin/ProcessSignalFormatterTest
COPY container/status-check.sh /usr/local/bin/status-check.sh

RUN echo "${MODULE_VERSION}" > /kernel-modules/MODULE_VERSION.txt && \
Expand Down
131 changes: 131 additions & 0 deletions collector/test/ProcessSignalFormatterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,137 @@ TEST(ProcessSignalFormatterTest, Rox3377ProcessLineageWithNoVPidTest) {
CollectorStats::Reset();
}

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

ProcessSignalFormatter processSignalFormatter(inspector.get(), config);

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";

sinsp_evt* evt = new sinsp_evt();
scap_evt* s_evt = new scap_evt();
s_evt->type = PPME_SYSCALL_EXECVE_19_X;

// An empty argument
tinfo->set_args("", 0);
evt->set_tinfo(tinfo.get());
evt->set_scap_evt(s_evt);

EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Empty argument failed";
}

TEST(ProcessSignalFormatterTest, LargeArgumentWithoutNull) {
std::unique_ptr<sinsp> inspector(new sinsp());
CollectorConfig config;
char* test;

ProcessSignalFormatter processSignalFormatter(inspector.get(), config);

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";

sinsp_evt* evt = new sinsp_evt();
scap_evt* s_evt = new scap_evt();
s_evt->type = PPME_SYSCALL_EXECVE_19_X;

// A large argument without a null terminator
test = (char*)malloc(8192);
memset(test, 0xff, 8192);

tinfo->set_args(test, 8192);
evt->set_tinfo(tinfo.get());
evt->set_scap_evt(s_evt);

EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Large argument without a null terminator failed";
}

TEST(ProcessSignalFormatterTest, SmallArgumentWithoutNull) {
std::unique_ptr<sinsp> inspector(new sinsp());
CollectorConfig config;
char* test;

ProcessSignalFormatter processSignalFormatter(inspector.get(), config);

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";

sinsp_evt* evt = new sinsp_evt();
scap_evt* s_evt = new scap_evt();
s_evt->type = PPME_SYSCALL_EXECVE_19_X;

// A small argument without a null terminator
test = (char*)malloc(200);
memset(test, 0xff, 200);

tinfo->set_args(test, 200);
evt->set_tinfo(tinfo.get());
evt->set_scap_evt(s_evt);

EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Small argument without a null terminator failed";
}

TEST(ProcessSignalFormatterTest, InvalidUTF8) {
std::unique_ptr<sinsp> inspector(new sinsp());
CollectorConfig config;
char* test;

ProcessSignalFormatter processSignalFormatter(inspector.get(), config);

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";

sinsp_evt* evt = new sinsp_evt();
scap_evt* s_evt = new scap_evt();
s_evt->type = PPME_SYSCALL_EXECVE_19_X;

// An argument with invalid UTF-8 sequence
test = (char*)malloc(200);
memset(test, 0xff, 200);
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;

tinfo->set_args(test, 200);
evt->set_tinfo(tinfo.get());
evt->set_scap_evt(s_evt);

EXPECT_NO_FATAL_FAILURE(processSignalFormatter.ToProtoMessage(evt)) << "Invalid UTF-8 argument failed";
}

} // namespace

} // namespace collector

0 comments on commit df79253

Please sign in to comment.