From a5b95ad0d6ee18f2deb9e98e3058efd12bf0f492 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 18 Jun 2019 18:03:33 +0300 Subject: Fix crashing on unhandled invalid_path thrown by extract_library_dirs() --- build2/cc/common.cxx | 54 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/build2/cc/common.cxx b/build2/cc/common.cxx index 085ed41..1bfb354 100644 --- a/build2/cc/common.cxx +++ b/build2/cc/common.cxx @@ -971,7 +971,7 @@ namespace build2 // Extract user-supplied search paths (i.e., -L, /LIBPATH). // - auto extract = [&r, this] (const value& val) + auto extract = [&r, this] (const value& val, const variable& what) { const auto& v (cast (val)); @@ -981,31 +981,39 @@ namespace build2 dir_path d; - if (cclass == compiler_class::msvc) + try { - // /LIBPATH: (case-insensitive). - // - if ((o[0] == '/' || o[0] == '-') && - casecmp (o.c_str () + 1, "LIBPATH:", 8) == 0) - d = dir_path (o, 9, string::npos); + if (cclass == compiler_class::msvc) + { + // /LIBPATH: (case-insensitive). + // + if ((o[0] == '/' || o[0] == '-') && + casecmp (o.c_str () + 1, "LIBPATH:", 8) == 0) + d = dir_path (o, 9, string::npos); + else + continue; + } else - continue; - } - else - { - // -L can either be in the "-L" or "-L " form. - // - if (o == "-L") { - if (++i == e) - break; // Let the compiler complain. + // -L can either be in the "-L" or "-L " form. + // + if (o == "-L") + { + if (++i == e) + break; // Let the compiler complain. - d = dir_path (*i); + d = dir_path (*i); + } + else if (o.compare (0, 2, "-L") == 0) + d = dir_path (o, 2, string::npos); + else + continue; } - else if (o.compare (0, 2, "-L") == 0) - d = dir_path (o, 2, string::npos); - else - continue; + } + catch (const invalid_path& e) + { + fail << "invalid path '" << e.path << "' in option '" << o + << "' in variable " << what; } // Ignore relative paths. Or maybe we should warn? @@ -1015,8 +1023,8 @@ namespace build2 } }; - if (auto l = bs[c_loptions]) extract (*l); - if (auto l = bs[x_loptions]) extract (*l); + if (auto l = bs[c_loptions]) extract (*l, c_loptions); + if (auto l = bs[x_loptions]) extract (*l, x_loptions); return r; } -- cgit v1.1