Skip to content

Commit b49ad24

Browse files
arirubinsteinpoiana
authored andcommitted
fix: if missing thread_entry, don't attempt to dereference it (iss-1076)
Signed-off-by: Ari Rubinstein <arirubinstein@users.noreply.github.com>
1 parent 5e6037d commit b49ad24

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed

plugins/container/src/caps/extract/extract.cpp

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <plugin.h>
2+
#include <optional>
23

34
//////////////////////////
45
// Extract capability
@@ -546,7 +547,7 @@ bool my_plugin::extract(const falcosecurity::extract_fields_input &in)
546547

547548
std::shared_ptr<const container_info> cinfo;
548549
std::string container_id;
549-
falcosecurity::table_entry thread_entry;
550+
std::optional<falcosecurity::table_entry> thread_entry;
550551

551552
// Async event. Is that produced by us?
552553
if(evt_type == PPME_ASYNCEVENT_E)
@@ -575,7 +576,8 @@ bool my_plugin::extract(const falcosecurity::extract_fields_input &in)
575576
// Retrieve the thread entry associated with this thread id
576577
thread_entry = m_threads_table.get_entry(tr, thread_id);
577578
// Retrieve container_id from the entry
578-
m_container_id_field.read_value(tr, thread_entry, container_id);
579+
m_container_id_field.read_value(tr, thread_entry.value(),
580+
container_id);
579581
}
580582
catch(const std::exception &e)
581583
{
@@ -763,15 +765,18 @@ bool my_plugin::extract(const falcosecurity::extract_fields_input &in)
763765
case TYPE_CONTAINER_START_TS:
764766
case TYPE_CONTAINER_DURATION:
765767
{
766-
uint64_t pidns_init_start_ts;
767-
try
768-
{
769-
m_threads_field_pidns_init_start_ts.read_value(tr, thread_entry,
770-
pidns_init_start_ts);
771-
}
772-
catch(...)
768+
uint64_t pidns_init_start_ts{0};
769+
if(thread_entry.has_value())
773770
{
774-
pidns_init_start_ts = 0;
771+
try
772+
{
773+
m_threads_field_pidns_init_start_ts.read_value(
774+
tr, thread_entry.value(), pidns_init_start_ts);
775+
}
776+
catch(...)
777+
{
778+
pidns_init_start_ts = 0;
779+
}
775780
}
776781
if(pidns_init_start_ts != 0)
777782
{
@@ -927,48 +932,61 @@ bool my_plugin::extract(const falcosecurity::extract_fields_input &in)
927932
break;
928933
case TYPE_IS_CONTAINER_HEALTHCHECK:
929934
{
930-
int16_t category;
935+
int16_t category{CAT_NONE};
931936
// Since we do write thread category only if not NONE for containerized
932937
// processes
933-
try
938+
if(thread_entry.has_value())
934939
{
935-
m_threads_field_category.read_value(tr, thread_entry, category);
936-
}
937-
catch(...)
938-
{
939-
category = CAT_NONE;
940+
try
941+
{
942+
m_threads_field_category.read_value(tr, thread_entry.value(),
943+
category);
944+
}
945+
catch(...)
946+
{
947+
category = CAT_NONE;
948+
}
940949
}
941950
req.set_value(category == CAT_HEALTHCHECK);
942951
break;
943952
}
944953
case TYPE_IS_CONTAINER_LIVENESS_PROBE:
945954
{
946-
int16_t category;
955+
int16_t category{CAT_NONE};
947956
// Since we do write thread category only if not NONE for containerized
948957
// processes
949-
try
958+
if(thread_entry.has_value())
950959
{
951-
m_threads_field_category.read_value(tr, thread_entry, category);
952-
}
953-
catch(...)
954-
{
955-
category = CAT_NONE;
960+
try
961+
{
962+
m_threads_field_category.read_value(tr, thread_entry.value(),
963+
category);
964+
}
965+
catch(...)
966+
{
967+
category = CAT_NONE;
968+
}
956969
}
957970
req.set_value(category == CAT_LIVENESS_PROBE);
958971
break;
959972
}
960973
case TYPE_IS_CONTAINER_READINESS_PROBE:
961974
{
962-
int16_t category;
975+
int16_t category{CAT_NONE};
963976
// Since we do write thread category only if not NONE for containerized
964977
// processes
965-
try
978+
if(thread_entry.has_value())
966979
{
967-
m_threads_field_category.read_value(tr, thread_entry, category);
968-
}
969-
catch(...)
970-
{
971-
category = CAT_NONE;
980+
981+
try
982+
{
983+
m_threads_field_category.read_value(tr, thread_entry.value(),
984+
category);
985+
}
986+
catch(...)
987+
{
988+
category = CAT_NONE;
989+
}
972990
}
973991
req.set_value(category == CAT_READINESS_PROBE);
974992
break;

0 commit comments

Comments
 (0)