autofs-5.1.9 - check map source in master_parse_entry()

From: Ian Kent <raven@themaw.net>

If a map entry is being updated check if the map source exists before
allocating a new one in master_parse_entry().

Also the source write lock should be used when updating the source
reference count.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG             |    1 +
 daemon/master.c       |    2 +-
 daemon/master_parse.y |   10 ++++------
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 04aeda7fe..2168a004b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -35,6 +35,7 @@
 - fix handling of ignored offsets.
 - fix invalidated map entry handling in hosts module.
 - dont call mkdir if dir exists.
+- check map source in master_parse_entry().
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/daemon/master.c b/daemon/master.c
index ece06414b..4448cf9a9 100644
--- a/daemon/master.c
+++ b/daemon/master.c
@@ -361,7 +361,7 @@ master_get_map_source(struct master_mapent *entry,
 {
 	struct map_source *source = NULL;
 
-	master_source_readlock(entry);
+	master_source_writelock(entry);
 	source = __master_find_map_source(entry, type, format, argc, argv);
 	if (source)
 		source->ref++;
diff --git a/daemon/master_parse.y b/daemon/master_parse.y
index 469cfe976..99279cd74 100644
--- a/daemon/master_parse.y
+++ b/daemon/master_parse.y
@@ -959,17 +959,15 @@ int master_parse_entry(const char *buffer, unsigned int default_timeout, unsigne
 		}
 	}
 
-/*
-	source = master_find_map_source(entry, type, format,
-					local_argc, (const char **) local_argv); 
+	source = NULL;
+	if (!new)
+		source = master_get_map_source(entry, type, format,
+					       local_argc, (const char **) local_argv);
 	if (!source)
 		source = master_add_map_source(entry, type, format, age, 
 					local_argc, (const char **) local_argv);
 	else
 		source->age = age;
-*/
-	source = master_add_map_source(entry, type, format, age, 
-					local_argc, (const char **) local_argv);
 	if (!source) {
 		error(m_logopt, "failed to add source");
 		if (new)
