From b2ac741e2b806f4565beeef34b12c95b6b3fdd41 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 31 Oct 2019 11:37:39 +0300 Subject: Fix unhandled invalid_path exception in path_search() --- libbutl/process.cxx | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'libbutl/process.cxx') diff --git a/libbutl/process.cxx b/libbutl/process.cxx index bc05c5c..e2a8af1 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -291,10 +291,20 @@ namespace butl } s.append (f, fn); - ep = path (move (s)); // Move back into result. - if (norm) - ep.normalize (); + // Assume that invalid path may not refer to an existing file. + // + try + { + ep = path (move (s)); // Move back into result. + + if (norm) + ep.normalize (); + } + catch (const invalid_path&) + { + return false; + } return exists (ep.string ().c_str ()); }; @@ -339,17 +349,10 @@ namespace butl e = strchr (b, traits::path_separator); // Empty path (i.e., a double colon or a colon at the beginning or end - // of PATH) means search in the current dirrectory. Silently skip - // invalid paths. + // of PATH) means search in the current directory. // - try - { - if (search (b, e != nullptr ? e - b : strlen (b))) - return r; - } - catch (const invalid_path&) - { - } + if (search (b, e != nullptr ? e - b : strlen (b))) + return r; } // If we were given a fallback, try that. -- cgit v1.1