ctest_submit: Escape URL components in CDASH_UPLOAD mode

Call curl_easy_escape on arguments sent to CDash upload.
This commit is contained in:
Bill Hoffman 2015-01-29 14:42:44 -05:00 committed by Brad King
parent a47b904db2
commit 18e3771ac7
3 changed files with 31 additions and 15 deletions

View File

@ -25,6 +25,21 @@ cmCTestCurl::cmCTestCurl(cmCTest* ctest)
this->VerifyPeerOff = false; this->VerifyPeerOff = false;
this->VerifyHostOff = false; this->VerifyHostOff = false;
this->TimeOutSeconds = 0; this->TimeOutSeconds = 0;
this->Curl = curl_easy_init();
}
cmCTestCurl::~cmCTestCurl()
{
::curl_easy_cleanup(this->Curl);
::curl_global_cleanup();
}
std::string cmCTestCurl::Escape(std::string const& source)
{
char* data1 = curl_easy_escape(this->Curl, source.c_str(), 0);
std::string ret = data1;
curl_free(data1);
return ret;
} }
namespace namespace
@ -73,7 +88,6 @@ void cmCTestCurl::SetCurlOptions(std::vector<std::string> const& args)
bool cmCTestCurl::InitCurl() bool cmCTestCurl::InitCurl()
{ {
this->Curl = curl_easy_init();
if(!this->Curl) if(!this->Curl)
{ {
return false; return false;
@ -160,7 +174,6 @@ bool cmCTestCurl::UploadFile(std::string const& local_file,
// Now run off and do what you've been told! // Now run off and do what you've been told!
::curl_easy_perform(this->Curl); ::curl_easy_perform(this->Curl);
::fclose(ftpfile); ::fclose(ftpfile);
::curl_global_cleanup();
if ( responseData.size() > 0 ) if ( responseData.size() > 0 )
{ {
@ -213,8 +226,6 @@ bool cmCTestCurl::HttpRequest(std::string const& url,
CURLcode res = ::curl_easy_perform(this->Curl); CURLcode res = ::curl_easy_perform(this->Curl);
::curl_easy_cleanup(this->Curl);
::curl_global_cleanup();
if ( responseData.size() > 0 ) if ( responseData.size() > 0 )
{ {
response = std::string(responseData.begin(), responseData.end()); response = std::string(responseData.begin(), responseData.end());

View File

@ -22,6 +22,7 @@ class cmCTestCurl
{ {
public: public:
cmCTestCurl(cmCTest*); cmCTestCurl(cmCTest*);
~cmCTestCurl();
bool UploadFile(std::string const& url, bool UploadFile(std::string const& url,
std::string const& file, std::string const& file,
std::string const& fields, std::string const& fields,
@ -34,6 +35,7 @@ public:
void SetCurlOptions(std::vector<std::string> const& args); void SetCurlOptions(std::vector<std::string> const& args);
void SetUseHttp10On() { this->UseHttp10 = true;} void SetUseHttp10On() { this->UseHttp10 = true;}
void SetTimeOutSeconds(int s) { this->TimeOutSeconds = s;} void SetTimeOutSeconds(int s) { this->TimeOutSeconds = s;}
std::string Escape(std::string const& source);
protected: protected:
void SetProxyType(); void SetProxyType();
bool InitCurl(); bool InitCurl();

View File

@ -1128,21 +1128,24 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
// TODO: Encode values for a URL instead of trusting caller. // TODO: Encode values for a URL instead of trusting caller.
std::ostringstream str; std::ostringstream str;
str << "project=" str << "project="
<< this->CTest->GetCTestConfiguration("ProjectName") << "&"; << curl.Escape(this->CTest->GetCTestConfiguration("ProjectName")) << "&";
if(subproject) if(subproject)
{ {
str << "subproject=" << subproject << "&"; str << "subproject=" << curl.Escape(subproject) << "&";
} }
str << "stamp=" << this->CTest->GetCurrentTag() << "-" str << "stamp=" << curl.Escape(this->CTest->GetCurrentTag()) << "-"
<< this->CTest->GetTestModelString() << "&" << curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "model=" << this->CTest->GetTestModelString() << "&" << "model=" << curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "build=" << this->CTest->GetCTestConfiguration("BuildName") << "&" << "build="
<< "site=" << this->CTest->GetCTestConfiguration("Site") << "&" << curl.Escape(this->CTest->GetCTestConfiguration("BuildName")) << "&"
<< "track=" << this->CTest->GetTestModelString() << "&" << "site="
<< curl.Escape(this->CTest->GetCTestConfiguration("Site")) << "&"
<< "track="
<< curl.Escape(this->CTest->GetTestModelString()) << "&"
<< "starttime=" << (int)cmSystemTools::GetTime() << "&" << "starttime=" << (int)cmSystemTools::GetTime() << "&"
<< "endtime=" << (int)cmSystemTools::GetTime() << "&" << "endtime=" << (int)cmSystemTools::GetTime() << "&"
<< "datafilesmd5[0]=" << md5sum << "&" << "datafilesmd5[0]=" << md5sum << "&"
<< "type=" << typeString; << "type=" << curl.Escape(typeString);
std::string fields = str.str(); std::string fields = str.str();
cmCTestLog(this->CTest, DEBUG, "fields: " << fields << "\nurl:" cmCTestLog(this->CTest, DEBUG, "fields: " << fields << "\nurl:"
<< url << "\nfile: " << file << "\n"); << url << "\nfile: " << file << "\n");
@ -1192,9 +1195,9 @@ int cmCTestSubmitHandler::HandleCDashUploadFile(std::string const& file,
std::string upload_as = cmSystemTools::GetFilenameName(file); std::string upload_as = cmSystemTools::GetFilenameName(file);
std::ostringstream fstr; std::ostringstream fstr;
fstr << "type=" << typeString << "&" fstr << "type=" << curl.Escape(typeString) << "&"
<< "md5=" << md5sum << "&" << "md5=" << md5sum << "&"
<< "filename=" << upload_as << "&" << "filename=" << curl.Escape(upload_as) << "&"
<< "buildid=" << json["buildid"].asString(); << "buildid=" << json["buildid"].asString();
if(!curl.UploadFile(file, url, fstr.str(), response)) if(!curl.UploadFile(file, url, fstr.str(), response))
{ {