aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-06-18 18:03:33 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-06-18 18:31:56 +0300
commita5b95ad0d6ee18f2deb9e98e3058efd12bf0f492 (patch)
treea99293a149688a1a94dd1324e9c86872dee982ea
parent7deb26b2e68321386afe2b2715a0e8a853dff352 (diff)
Fix crashing on unhandled invalid_path thrown by extract_library_dirs()
-rw-r--r--build2/cc/common.cxx54
1 files 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<strings> (val));
@@ -981,31 +981,39 @@ namespace build2
dir_path d;
- if (cclass == compiler_class::msvc)
+ try
{
- // /LIBPATH:<dir> (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:<dir> (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<dir>" or "-L <dir>" form.
- //
- if (o == "-L")
{
- if (++i == e)
- break; // Let the compiler complain.
+ // -L can either be in the "-L<dir>" or "-L <dir>" 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;
}