bug #1781: Replaces " by ' and escape ' using '\''. context.sh should be now sh-syntax secure

(cherry picked from commit 306aff8906)
This commit is contained in:
Ruben S. Montero committed 2013-06-21 21:06:29 +02:00
1 parent 14147a48f3
commit ab0c98a746
1 file changed
+11 -1
+11 -1
View File
@@ -2417,7 +2417,17 @@ int VirtualMachine::generate_context(string &files, int &disk_id)
for (it=values.begin(); it != values.end(); it++ )
{
file << it->first <<"=\""<< it->second << "\"" << endl;
//Replace every ' in value by '\''
string escape_str(it->second);
size_t pos = 0;
while ((pos = escape_str.find('\'', pos)) != string::npos)
{
escape_str.replace(pos,1,"'\\''");
pos = pos + 4;
}
file << it->first <<"='" << escape_str << "'" << endl;
}
file.close();