bug #1264: Do not allow wrong number in GRAPHICS/PORT; i.e. floats, <0, strings...

(cherry picked from commit d1b71d0df1)
This commit is contained in:
Ruben S. Montero authored and Javi Fontan committed 2013-11-21 16:26:47 +01:00
1 parent 851c708a56
commit a6be61bb2a
3 files changed
+25 -11

No files matched your search

+1 -1
View File
@@ -1612,7 +1612,7 @@ private:
* Parse the "GRAPHICS" attribute and generates a default PORT if not
* defined
*/
void parse_graphics();
int parse_graphics(string& error_str);
/**
* Searches the meaningful attributes and moves them from the user template
+3 -3
View File
@@ -256,9 +256,9 @@ int Host::update_info(Template &tmpl,
vector<Attribute*> ds_att;
vector<Attribute*> local_ds_att;
int rc;
int vmid;
long long val;
int rc;
int vmid;
float val;
string error_st;
+21 -7
View File
@@ -392,7 +392,10 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
goto error_requirements;
}
parse_graphics();
if ( parse_graphics(error_str) != 0 )
{
goto error_graphics;
}
parse_well_known_attributes();
@@ -418,6 +421,9 @@ error_context:
error_requirements:
goto error_rollback;
error_graphics:
goto error_rollback;
error_rollback:
release_disk_images();
@@ -917,16 +923,14 @@ error_cleanup:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::parse_graphics()
int VirtualMachine::parse_graphics(string& error_str)
{
int num;
vector<Attribute *> array_graphics;
VectorAttribute * graphics;
vector<Attribute *>::iterator it;
num = user_obj_template->remove("GRAPHICS", array_graphics);
int num = user_obj_template->remove("GRAPHICS", array_graphics);
for (it=array_graphics.begin(); it != array_graphics.end(); it++)
{
@@ -935,17 +939,20 @@ void VirtualMachine::parse_graphics()
if ( num == 0 )
{
return;
return 0;
}
graphics = dynamic_cast<VectorAttribute * >(array_graphics[0]);
if ( graphics == 0 )
{
return;
return 0;
}
string port = graphics->vector_value("PORT");
int port_i;
int rc = graphics->vector_value("PORT", port_i);
if ( port.empty() )
{
@@ -966,6 +973,13 @@ void VirtualMachine::parse_graphics()
oss << ( base_port + ( oid % (limit - base_port) ));
graphics->replace("PORT", oss.str());
}
else if ( rc == -1 || port_i < 0 )
{
error_str = "Wrong PORT number in GRAPHICS attribute";
return -1;
}
return 0;
}
/* -------------------------------------------------------------------------- */