From 81a817a46c04c7b677ddb08bee10ecf35ae3084a Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 5 Jun 2024 16:10:20 -0400 Subject: [PATCH] Fix #???, address sanitizer failure in FS Add self-defense check in CFE_FS_ParseInputFileNameEx() in case the input buffer size passed in is greater than the length of the input string. Technically, this could be argued as an incorrect call/input, but it is something the function could check for and avoid reading past the final null char. --- modules/fs/fsw/src/cfe_fs_api.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/fs/fsw/src/cfe_fs_api.c b/modules/fs/fsw/src/cfe_fs_api.c index fbd0e54a0..c382b5e8b 100644 --- a/modules/fs/fsw/src/cfe_fs_api.c +++ b/modules/fs/fsw/src/cfe_fs_api.c @@ -405,8 +405,17 @@ int32 CFE_FS_ParseInputFileNameEx(char *OutputBuffer, const char *InputBuffer, s /* If input buffer is not empty, then use it, otherwise use DefaultInput */ if (InputBuffer != NULL && InputBufSize > 0 && InputBuffer[0] != 0) { + InputPtr = memchr(InputBuffer, 0, InputBufSize); + if (InputPtr != NULL) + { + InputLen = InputPtr - InputBuffer; + } + else + { + InputLen = InputBufSize; + } + InputPtr = InputBuffer; - InputLen = InputBufSize; } else if (DefaultInput != NULL) {