From 0d271d5f151002644f586b1e76cd237b153831b5 Mon Sep 17 00:00:00 2001
From: Marios Makassikis <mmakassikis@freebox.fr>
Date: Wed, 2 Nov 2022 17:36:17 +0100
Subject: [PATCH] ksmbd-tools: config_parser: fix out of bounds read in
 __mmap_parse_file

If 'contents' is not null terminated, strchr() will walk past the end of
the buffer.

---
 lib/config_parser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/config_parser.c b/lib/config_parser.c
index b8b20570893c..9286624d7e52 100644
--- a/lib/config_parser.c
+++ b/lib/config_parser.c
@@ -222,7 +222,7 @@ static int __mmap_parse_file(const char *fname, int (*callback)(char *data))
 
 	len = g_mapped_file_get_length(file);
 	while (len > 0) {
-		delim = strchr(contents, '\n');
+		delim = memchr(contents, '\n', len);
 		if (!delim)
 			delim = contents + len - 1;
 
-- 
2.25.1

