You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2011/06/05 08:39:04 UTC
svn commit: r1131941 - /incubator/mesos/trunk/src/configurator.cpp
Author: benh
Date: Sun Jun 5 06:39:03 2011
New Revision: 1131941
URL: http://svn.apache.org/viewvc?rev=1131941&view=rev
Log:
Fixed a bug in configurator - initializing from argc/argv could change
argv[0] on some platforms because dirname() is allowed to modify its
input string.
Modified:
incubator/mesos/trunk/src/configurator.cpp
Modified: incubator/mesos/trunk/src/configurator.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/configurator.cpp?rev=1131941&r1=1131940&r2=1131941&view=diff
==============================================================================
--- incubator/mesos/trunk/src/configurator.cpp (original)
+++ incubator/mesos/trunk/src/configurator.cpp Sun Jun 5 06:39:03 2011
@@ -118,12 +118,19 @@ void Configurator::loadCommandLine(int a
{
// Set home based on argument 0 if asked to do so
if (inferMesosHomeFromArg0) {
- char buf[4096];
- if (realpath(dirname(argv[0]), buf) == 0) {
+ // Copy argv[0] because dirname can modify it
+ int lengthOfArg0 = strlen(argv[0]);
+ char* copyOfArg0 = new char[lengthOfArg0 + 1];
+ strcpy(copyOfArg0, argv[0]);
+ // Get the directory name from it
+ char* buf = new char[lengthOfArg0 + 1];
+ if (realpath(dirname(copyOfArg0), buf) == 0) {
throw ConfigurationException(
"Could not get directory containing argv[0] -- realpath failed");
}
params["home"] = buf;
+ delete[] copyOfArg0;
+ delete[] buf;
}
// Convert args 1 and above to STL strings