From 23d08820a2bec1182c838de34cc2c6687dc95558 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 7 Oct 2019 12:23:58 +0200
Subject: [PATCH] db/update/Walk: fix crash when music_directory is not a
 directory

Add a runtime sanity check to avoid the assertion failure.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/660
---
 NEWS                   | 2 ++
 src/db/update/Walk.cxx | 6 ++++++
 2 files changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index faf11c231..334cce603 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.21.16 (not yet released)
+* update
+  - fix crash when music_directory is not a directory
 
 ver 0.21.15 (2019/09/25)
 * decoder
diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx
index c13d6fd40..e2c9b7a8c 100644
--- a/src/db/update/Walk.cxx
+++ b/src/db/update/Walk.cxx
@@ -493,6 +493,12 @@ UpdateWalk::Walk(Directory &root, const char *path, bool discard) noexcept
 		if (!GetInfo(storage, "", info))
 			return false;
 
+		if (!info.IsDirectory()) {
+			FormatError(update_domain, "Not a directory: %s",
+				    storage.MapUTF8("").c_str());
+			return false;
+		}
+
 		ExcludeList exclude_list;
 
 		UpdateDirectory(root, exclude_list, info);