From da108f67e1b297d8855d18e9d136d4e87c97712e Mon Sep 17 00:00:00 2001 From: Roberto Scolaro Date: Mon, 6 Jan 2025 11:41:53 +0000 Subject: [PATCH] fix(libsinsp/runc): avoid throwing exception in case of short container id Signed-off-by: Roberto Scolaro --- userspace/libsinsp/runc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/userspace/libsinsp/runc.cpp b/userspace/libsinsp/runc.cpp index 5e4f482219..a61b083aef 100644 --- a/userspace/libsinsp/runc.cpp +++ b/userspace/libsinsp/runc.cpp @@ -84,7 +84,10 @@ bool match_one_container_id(const std::string &cgroup, return false; } - container_id = cgroup.substr(start_pos, REPORTED_CONTAINER_ID_LENGTH); + size_t reported_len = end_pos - start_pos >= REPORTED_CONTAINER_ID_LENGTH + ? REPORTED_CONTAINER_ID_LENGTH + : end_pos; + container_id = cgroup.substr(start_pos, reported_len); return true; }