From 1d4c57222faffe1e84b4b48d08dbbdf12a359865 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Fri, 29 Oct 2021 09:04:55 -0700 Subject: [PATCH] Validate path starts with source and ends with destination --- .../serve/mappers/internal/graph/search.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/commands/serve/mappers/internal/graph/search.rb b/plugins/commands/serve/mappers/internal/graph/search.rb index 4c1a3b43d..d6833b507 100644 --- a/plugins/commands/serve/mappers/internal/graph/search.rb +++ b/plugins/commands/serve/mappers/internal/graph/search.rb @@ -56,12 +56,23 @@ module VagrantPlugins # Apply topological sort to the graph so we have # a proper for execution - Array.new.tap do |path| + result = Array.new.tap do |path| t = graph.topsort_iterator until t.at_end? path << t.forward end end + + if result.first != src + raise NoPathError, + "Initial vertex is not source #{src} != #{result.first}" + end + + if result.last != dst + raise NoPathError, + "Final vertex is not destination #{dst} != #{result.last}" + end + result end end @@ -70,6 +81,10 @@ module VagrantPlugins def generate_path(src, dst) begin path = graph.shortest_path(src, dst) + o = Array(path).map { |v| + "#{v} ->" + }.join("\n") + logger.debug("path generation #{src} -> #{dst}\n#{o}") if path.nil? raise NoPathError, "Path generation failed to reach destination (#{dst&.type&.inspect})"