summaryrefslogtreecommitdiffstats
path: root/llvm/utils
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2008-11-12 12:41:18 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2008-11-12 12:41:18 +0000
commita2909684b64c8be489d4f83adf609def104fdef3 (patch)
treef2bb6289255478857bf38799d80260d3089d2a87 /llvm/utils
parent2889780436ebc7feccb81aa11117e8a0a4de42ed (diff)
downloadbcm5719-llvm-a2909684b64c8be489d4f83adf609def104fdef3.tar.gz
bcm5719-llvm-a2909684b64c8be489d4f83adf609def104fdef3.zip
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. llvm-svn: 59131
Diffstat (limited to 'llvm/utils')
-rw-r--r--llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp b/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp
index 33b0e3d8cb2..bacde538daa 100644
--- a/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp
+++ b/llvm/utils/TableGen/LLVMCConfigurationEmitter.cpp
@@ -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
OpenPOWER on IntegriCloud