From bbf55383e7a9914cf79b8879e234f444cc774bfa Mon Sep 17 00:00:00 2001
From: Robert Hensing <robert@roberthensing.nl>
Date: Sat, 26 Feb 2022 02:30:29 +0100
Subject: [PATCH] Value::mkPath: Avoid potential crash from null string_view

---
 src/libexpr/eval.cc | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index b954e7bd9..7f82aa5f4 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -842,7 +842,14 @@ void Value::mkStringMove(const char * s, const PathSet & context)
 
 void Value::mkPath(std::string_view s)
 {
-    mkPath(dupStringWithLen(s.data(), s.size()));
+    if (s.size() == 0) {
+        // Pathological, but better than crashing in dupStringWithLen, as
+        // s.data() may be null.
+        mkPath("");
+    }
+    else {
+        mkPath(dupStringWithLen(s.data(), s.size()));
+    }
 }