autofs-5.1.9 - dont assume non null tree node in tree_free()

From: Ian Kent <raven@themaw.net>

Be defensive in the tree_free() function, only dereference the passed
in tree node if it isn't NULL.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG    |    1 +
 lib/mounts.c |   14 ++++++++------
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 66450d701..077c4ae54 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -57,6 +57,7 @@
 - fix error return in do_mount_indirect().
 - use sizeof for buffer length in set_log_priority.
 - fix sublink option check length in update_with_defaults().
+- dont assume non null tree node in tree_free().
 
 02/11/2023 autofs-5.1.9
 - fix kernel mount status notification.
diff --git a/lib/mounts.c b/lib/mounts.c
index 662a2a8b2..6061f91e5 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -1407,13 +1407,15 @@ static struct tree_node *tree_add_node(struct tree_node *root, void *ptr)
 
 void tree_free(struct tree_node *root)
 {
-	struct tree_ops *ops = root->ops;
+	if (root) {
+		struct tree_ops *ops = root->ops;
 
-	if (root->right)
-		tree_free(root->right);
-	if (root->left)
-		tree_free(root->left);
-	ops->free(root);
+		if (root->right)
+			tree_free(root->right);
+		if (root->left)
+			tree_free(root->left);
+		ops->free(root);
+	}
 }
 
 int tree_traverse_inorder(struct tree_node *n, tree_work_fn_t work, void *ptr)
