From 538771a44a6c5f54490ca719cea4ef99230087e5 Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Fri, 27 Jun 2025 15:37:52 -0700 Subject: [PATCH 1/3] [XPTI] Add assert to prevent unintentional integer underflow. --- xptifw/src/xpti_trace_framework.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index f3c9272655f21..95807c0779ad7 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -1193,7 +1193,15 @@ class Tracepoints { if ((Payload->flags & static_cast(xpti::payload_flag_t::SourceFileAvailable))) { // Add source file information ot string table - FileId = MStringTableRef.add(Payload->source_file, &Payload->source_file); + + // MStringTableRef.add returns a string_id_t which is an int32_t and can + // be negative. If it's negative, it indicates an error and we should + // throw. + int32_t PFileId = + MStringTableRef.add(Payload->source_file, &Payload->source_file); + + assert(PFileId >= 0 && "FileId can't be negative"); + FileId = static_cast(PFileId); LineNo = Payload->line_no; ColNo = Payload->column_no; } From 7c8234ca76cd447d56113e57f3c567dc18964449 Mon Sep 17 00:00:00 2001 From: Udit Kumar Agarwal Date: Mon, 30 Jun 2025 10:19:22 -0700 Subject: [PATCH 2/3] Update xptifw/src/xpti_trace_framework.cpp --- xptifw/src/xpti_trace_framework.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index 95807c0779ad7..8c5aacc000b64 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -1195,8 +1195,7 @@ class Tracepoints { // Add source file information ot string table // MStringTableRef.add returns a string_id_t which is an int32_t and can - // be negative. If it's negative, it indicates an error and we should - // throw. + // be negative, but negative values are unexpected in this context. int32_t PFileId = MStringTableRef.add(Payload->source_file, &Payload->source_file); From 3c7f1b9d4d11aa2da9ccaf4c17ebd5767a43273d Mon Sep 17 00:00:00 2001 From: "Agarwal, Udit" Date: Mon, 30 Jun 2025 10:25:45 -0700 Subject: [PATCH 3/3] Fix merge conflict --- xptifw/src/xpti_trace_framework.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xptifw/src/xpti_trace_framework.cpp b/xptifw/src/xpti_trace_framework.cpp index 0923e3721a388..264ad2122ecc4 100644 --- a/xptifw/src/xpti_trace_framework.cpp +++ b/xptifw/src/xpti_trace_framework.cpp @@ -1275,7 +1275,7 @@ class Tracepoints { static_cast(xpti::payload_flag_t::NameAvailable); // If the function name is not available, we will use the global unknown FuncId = xpti::hash::fnv1a(Payload->name); - + } // If the payload's source file is available, generate a fast hash as its // ID; Since reverse lookup is not necessary for callback functions, we