简体   繁体   English

在“发送垃圾邮件”时提升访问权限:: property_tree :: read_json

[英]Access violation while “spamming” boost::property_tree::read_json

I've made a simple TCP Server using Boost Asio (1.53.0). 我使用Boost Asio (1.53.0)制作了一个简单的TCP Server。 The Server accepts JSON-Requests, parse them with boost::property_tree::read_json . 服务器接受JSON请求,并使用boost :: property_tree :: read_json解析它们。

To test the reliability, I created a simple Application which creates 128 Threads and they send continually Requests. 为了测试可靠性,我创建了一个简单的应用程序,该应用程序创建了128个线程,它们不断发送请求。

After a few seconds, the server crashes with an Access Violation: 几秒钟后,服务器因访问冲突而崩溃:

Unhandled exception at 0x000007FEFD829E5D (KernelBase.dll) in RPC_Server.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

msvcr110d.dll!__RethrowException(EHExceptionRecord * pThisException) Line 1217
msvcr110d.dll!__CxxCallCatchBlock(_EXCEPTION_RECORD * pExcept) Line 1279
ntdll.dll!0000000077360c21()
RPC_Server.exe!json::json::Parse(std::basic_string<char,std::char_traits<char>,std::allocator<char> > & sJson) Line 28

Here get's read_json called: 这里得到的read_json称为:

rpc::request json::Parse(std::string sJson)
{
  try {
    std::stringstream ss;
    ss << sJson;
    boost::property_tree::ptree pt;
    boost::property_tree::read_json(ss, pt);
...
}
  • If I comment the read_json line out, the server handles everything correctly. 如果我将read_json行注释掉,则服务器将正确处理所有内容。
  • If I reduce the Test Application to eg just 1 Thread, the server handles and parses everything correctly. 如果我将“测试应用程序”减少到仅1个线程,则服务器将正确处理并解析所有内容。

Seems like boost::property_tree::read_json isn't thread-safe by default. 似乎boost :: property_tree :: read_json默认情况下不是线程安全的。

You have to define: 您必须定义:

#define BOOST_SPIRIT_THREADSAFE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM