From 77278f5d4e13f9bfed1320aae0d5bcfc5050163e Mon Sep 17 00:00:00 2001
From: Marios Makassikis <mmakassikis@freebox.fr>
Date: Sun, 30 Oct 2022 22:09:20 +0100
Subject: [PATCH 2/3] ksmbd-tools: config_parser: fix crash on invalid config
 parsing

A malformed config file will crash mountd. If key/value pairs occur
before a configuration group has been defined. Example:

; key value pair outside of config group
max connections = 10
[example]
	comment = example share
	path = /tmp

Signed-off-by: Marios Makassikis <mmakassikis@freebox.fr>
---
 lib/config_parser.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/config_parser.c b/lib/config_parser.c
index 5227d67bdc11..b8b20570893c 100644
--- a/lib/config_parser.c
+++ b/lib/config_parser.c
@@ -159,6 +159,13 @@ static int add_group_key_value(char *line)
 		return -ENOMEM;
 	}
 
+	if (!parser.current) {
+		pr_err("Key-value definition for `%s' is not in a group\n", key);
+		g_free(key);
+		g_free(value);
+		return -EINVAL;
+	}
+
 	if (g_hash_table_lookup(parser.current->kv, key)) {
 		pr_info("Multiple key-value definitions for `%s' in group `%s'\n",
 			key, parser.current->name);
-- 
2.25.1

