From 7b56e3f90be0efece268e85832dd9828a7490b13 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 17 Mar 2022 09:00:28 +0200 Subject: Diagnose invalid paths in -print-search-dirs output For example, some mis-configured MinGW GCC builds include /mingw/lib. --- libbuild2/cc/gcc.cxx | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'libbuild2/cc') diff --git a/libbuild2/cc/gcc.cxx b/libbuild2/cc/gcc.cxx index 30f2092..3376c16 100644 --- a/libbuild2/cc/gcc.cxx +++ b/libbuild2/cc/gcc.cxx @@ -153,7 +153,8 @@ namespace build2 // // For now we ignore framework paths and to filter them out we will // only consider valid paths to existing directories, skipping those - // which we fail to normalize or stat. + // which we fail to normalize or stat. @@ Maybe this is a bit too + // loose, especially compared to gcc_library_search_dirs()? // string s; for (bool found (false); getline (is, s); ) @@ -165,18 +166,23 @@ namespace build2 if (s[0] != ' ') break; + dir_path d; try { - dir_path d (s, 1, s.size () - 1); + d = dir_path (s, 1, s.size () - 1); - if (d.absolute () && exists (d, true) && - find (r.begin (), r.end (), d.normalize ()) == r.end ()) - r.emplace_back (move (d)); + if (d.relative () || !exists (d, true)) + continue; + + d.normalize (); } catch (const invalid_path&) { - // Skip this path. + continue; } + + if (find (r.begin (), r.end (), d) == r.end ()) + r.emplace_back (move (d)); } } @@ -334,9 +340,23 @@ namespace build2 // for (string::size_type b (0);; e = l.find (d, (b = e + 1))) { - dir_path d (l, b, (e != string::npos ? e - b : e)); + dir_path d; + try + { + d = dir_path (l, b, (e != string::npos ? e - b : e)); + + if (d.relative ()) + throw invalid_path (move (d).string ()); + + d.normalize (); + } + catch (const invalid_path& e) + { + fail << "invalid directory '" << e.path << "'" << " in " + << args[0] << " -print-search-dirs output"; + } - if (find (r.begin (), r.end (), d.normalize ()) == r.end ()) + if (find (r.begin (), r.end (), d) == r.end ()) r.emplace_back (move (d)); if (e == string::npos) -- cgit v1.1