diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index cd93408c2e..6a8d8ccec6 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -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 diff --git a/src/host/Host.cc b/src/host/Host.cc index 4f72927084..f84f3bc2d0 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -256,9 +256,9 @@ int Host::update_info(Template &tmpl, vector ds_att; vector local_ds_att; - int rc; - int vmid; - long long val; + int rc; + int vmid; + float val; string error_st; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 53b91fdaae..bc0185519d 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -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 array_graphics; VectorAttribute * graphics; vector::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(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; } /* -------------------------------------------------------------------------- */