Commit 9aa37abb authored by Millian Poquet's avatar Millian Poquet
Browse files

[code] safer rapidjson buffer access

parent bc7f8737
......@@ -245,7 +245,7 @@ Job * Job::from_json(const rapidjson::Value & json_desc,
json_desc.Accept(writer);
// Let's replace the job ID by its WLOAD!NUMBER counterpart
string json_description_tmp = buffer.GetString();
string json_description_tmp(buffer.GetString(), buffer.GetSize());
boost::regex r("\"id\"\\s*:\\s*(?:\".+\"|\\d+)\\s*");
string replacement_str = "\"id\":\"" + workload_name + "!" + std::to_string(j->number) + "\"";
j->json_description = boost::regex_replace(json_description_tmp, r, replacement_str);
......
......@@ -383,7 +383,7 @@ Profile *Profile::from_json(const std::string & profile_name,
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
json_desc.Accept(writer);
profile->json_description = buffer.GetString();
profile->json_description = string(buffer.GetString(), buffer.GetSize());
return profile;
}
......
......@@ -352,7 +352,7 @@ string JsonProtocolWriter::generate_current_message(double date)
_doc.Accept(writer);
// Returning the buffer as a string
return string(buffer.GetString());
return string(buffer.GetString(), buffer.GetSize());
}
......@@ -775,10 +775,9 @@ void JsonProtocolReader::handle_submit_job(int event_number,
StringBuffer buffer;
::Writer<rapidjson::StringBuffer> writer(buffer);
job_object.Accept(writer);
message->job_description = string(buffer.GetString());
message->job_description = string(buffer.GetString(), buffer.GetSize());
}
else
xbt_assert(context->redis_enabled, "Invalid JSON message: in event %d (SUBMIT_JOB): ['data']['job'] is unset but redis seems enabled...", event_number);
......@@ -792,10 +791,9 @@ void JsonProtocolReader::handle_submit_job(int event_number,
StringBuffer buffer;
::Writer<rapidjson::StringBuffer> writer(buffer);
profile_object.Accept(writer);
message->job_profile = string(buffer.GetString());
message->job_profile_description = string(buffer.GetString(), buffer.GetSize());
}
else
xbt_assert(context->redis_enabled, "Invalid JSON message: in event %d (SUBMIT_JOB): ['data']['profile'] is unset but redis seems enabled...", event_number);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment