mirror of
https://github.com/RPCS3/llvm.git
synced 2025-02-21 11:11:42 +00:00
Check the return value of std::getenv.
When constructing std::strings from C strings, we should check the input value to be not NULL so that the std::string constructor does not segfault. Fixes #3047. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9a365b6acb
commit
6766572dcb
@ -1121,9 +1121,9 @@ std::string SubstituteSpecialCommands(const std::string& cmd) {
|
||||
if (cmd.size() == 5)
|
||||
throw std::string("$ENV invocation: empty argument list!");
|
||||
|
||||
ret += "std::getenv(\"";
|
||||
ret += "checkCString(std::getenv(\"";
|
||||
ret += std::string(cmd.begin() + 5, cmd.begin() + cparen);
|
||||
ret += "\")";
|
||||
ret += "\"))";
|
||||
}
|
||||
else {
|
||||
throw "Unknown special command: " + cmd;
|
||||
@ -1729,7 +1729,8 @@ void EmitRegisterPlugin(std::ostream& O) {
|
||||
<< "static llvmc::RegisterPlugin<Plugin> RP;\n\n}\n\n";
|
||||
}
|
||||
|
||||
/// EmitInclude - Emit necessary #include directives.
|
||||
/// EmitIncludes - Emit necessary #include directives and some
|
||||
/// additional declarations.
|
||||
void EmitIncludes(std::ostream& O) {
|
||||
O << "#include \"llvm/CompilerDriver/CompilationGraph.h\"\n"
|
||||
<< "#include \"llvm/CompilerDriver/Plugin.h\"\n"
|
||||
@ -1744,7 +1745,10 @@ void EmitIncludes(std::ostream& O) {
|
||||
<< "using namespace llvm;\n"
|
||||
<< "using namespace llvmc;\n\n"
|
||||
|
||||
<< "extern cl::opt<std::string> OutputFilename;\n\n";
|
||||
<< "extern cl::opt<std::string> OutputFilename;\n\n"
|
||||
|
||||
<< "inline const char* checkCString(const char* s)\n"
|
||||
<< "{ return s == NULL ? \"\" : s; }\n\n";
|
||||
}
|
||||
|
||||
// End of anonymous namespace
|
||||
|
Loading…
x
Reference in New Issue
Block a user