From 355fc8784ba16fb9437301833e86c2cd30c451b7 Mon Sep 17 00:00:00 2001
From: Marios Makassikis <mmakassikis@freebox.fr>
Date: Sun, 30 Oct 2022 21:49:22 +0100
Subject: [PATCH 1/3] ksmbd-tools: config_parser: don't crash on empty key

An invalid conf with an empty key (' = val') will crash mountd as a
negative length is passed to g_strndup.

---
 lib/config_parser.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/config_parser.c b/lib/config_parser.c
index b643e4dccbe3..5227d67bdc11 100644
--- a/lib/config_parser.c
+++ b/lib/config_parser.c
@@ -137,13 +137,15 @@ static int add_group_key_value(char *line)
 
 	value = key;
 	*key = 0x00;
-	key--;
-	value++;
 
-	while (is_ascii_space_tab(*key))
-		key--;
-	while (is_ascii_space_tab(*value))
-		value++;
+	do {
+		if (key == line)
+			return -EINVAL;
+	} while (is_ascii_space_tab(*--key));
+
+	do {
+		;
+	} while (is_ascii_space_tab(*++value));
 
 	if (is_a_comment(value))
 		return 0;
-- 
2.25.1

