From 8ac9a080bee25e67e49bd138d81c992ce7b6d899 Mon Sep 17 00:00:00 2001
From: Michael Methner <mmethner@de.adit-jv.com>
Date: Fri, 27 Jan 2023 10:51:07 +0100
Subject: [PATCH] Check for negative index in dlt_file_message

Fixes #436

Signed-off-by: Michael Methner <mmethner@de.adit-jv.com>

CVE: CVE-2023-36321
Upstream-Status: Backport [https://github.com/michael-methner/dlt-daemon/commit/8ac9a080bee25e67e49bd138d81c992ce7b6d899]

Signed-off-by: Yogita Urade <yogita.urade@windriver.com>
---
 src/shared/dlt_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index 4303c50..34da70a 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -1718,7 +1718,7 @@ DltReturnValue dlt_file_message(DltFile *file, int index, int verbose)
         return DLT_RETURN_WRONG_PARAMETER;

     /* check if message is in range */
-    if (index >= file->counter) {
+    if (index < 0 || index >= file->counter) {
         dlt_vlog(LOG_WARNING, "Message %d out of range!\r\n", index);
         return DLT_RETURN_WRONG_PARAMETER;
     }
--
2.40.0
