Advertisement
Guest User

Untitled

a guest
Feb 16th, 2011
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.76 KB | None | 0 0
  1.     void doTest(bool& failed)
  2.     {
  3.         ReceiveHelper helper(failed);
  4.  
  5.         boost::threadpool::pool pool(2);
  6.         int port = 55600;
  7.         boost::asio::io_service service;
  8.         udp::endpoint thisPoint = udp::endpoint(address::from_string("127.0.0.1"),
  9.                 port);
  10.         udp::endpoint receivePoint;
  11.         udp::socket socket(service, thisPoint);
  12.         socket.async_receive_from(boost::asio::buffer(helper.buffer), receivePoint, boost::bind(&ReceiveHelper::handleReceive,
  13.                 &helper, boost::asio::placeholders::error,
  14.                 boost::asio::placeholders::bytes_transferred));
  15.         pool.schedule(boost::bind(&boost::asio::io_service::run, &service));
  16.         voip::network::client::UdpClient client;
  17.         client.connect(thisPoint);
  18.         client.send(1, "Hello!");
  19.         boost::this_thread::sleep(boost::posix_time::milliseconds(1));
  20.         service.stop();
  21.     }
  22.  
  23. class ReceiveHelper {
  24.     private:
  25.         bool& failed;
  26.  
  27.         public:
  28.             ReceiveHelper(bool & failed) : failed(failed), buffer()
  29.             {
  30.  
  31.             }
  32.             boost::array<uint8_t, BUF_SIZE> buffer;
  33.             void handleReceive(const boost::system::error_code & error, size_t numBytes)
  34.             {
  35.                 if(numBytes != 8)
  36.                     return;
  37.                 if(std::string((char*)buffer.c_array(), 6) != "Hello!")
  38.                     return;
  39.                 failed = false;
  40.             }
  41.     };
  42.  
  43.     void UdpClient::send(uint8_t handler, std::string message)
  44.     { <-------------------------------------------------------------------------------------- Canary at this point fails
  45.         ClientSendContext context(*this);
  46.         ClientConnection::send(context, handler, message);
  47.     } <-------------------------------------------------------------------------------------- Canary at this point fails
  48.  
  49.         void send(SendContext & sendContext, uint8_t handler, std::string & message)
  50.         {
  51.             uint8_t *array = new uint8_t[message.size() + 2];
  52.             memcpy(array, message.c_str(), message.size());
  53.             boost::asio::mutable_buffer buffer(array, message.size() + 2);
  54.             prepareMessage(handler, buffer);
  55.             sendContext.send(buffer);
  56.             delete[] array;
  57.         }
  58.  
  59.         size_t prepareMessage(uint8_t handler, boost::asio::mutable_buffer message)
  60.         {
  61.             size_t messageLength = boost::asio::buffer_size(message);
  62.             uint8_t* data = boost::asio::buffer_cast<uint8_t*>(message);
  63.             data[messageLength - 1] = network::handler;
  64.             data[messageLength - 2] = handler;
  65.             return messageLength;
  66.         }
  67.  
  68. *** stack smashing detected ***: ./testclient terminated
  69. ======= Backtrace: =========
  70. /lib/libc.so.6(__fortify_fail+0x37)[0x58e9537]
  71. /lib/libc.so.6(__fortify_fail+0x0)[0x58e9500]
  72. ./testclient(_ZN4voip7network6client9UdpClient4sendEhSs+0x85)[0x46b449]
  73. ./testclient(_ZN4voip4test6client18SuiteTestUdpClient6doTestERb+0x2dd)[0x44c7c1]
  74. ./testclient(_ZNK4voip4test6client18SuiteTestUdpClient17TestClientCanSend7RunImplEv+0x2f)[0x44c957]
  75. ./testclient(_ZN8UnitTest11ExecuteTestINS_4TestEEEvRT_RKNS_11TestDetailsE+0x9a)[0x469551]
  76. ./testclient(_ZN8UnitTest4Test3RunEv+0x23)[0x46920f]
  77. ./testclient(_ZNK8UnitTest10TestRunner7RunTestEPNS_11TestResultsEPNS_4TestEi+0x7c)[0x469b74]
  78. ./testclient(_ZNK8UnitTest10TestRunner10RunTestsIfINS_4TrueEEEiRKNS_8TestListEPKcRKT_i+0x8f)[0x469ddb]
  79. ./testclient(_ZN8UnitTest11RunAllTestsEv+0x53)[0x4697b7]
  80. ./testclient(main+0x9)[0x44ca62]
  81. /lib/libc.so.6(__libc_start_main+0xfe)[0x5808d8e]
  82. ./testclient[0x44c429]
  83. ======= Memory map: ========
  84. 00400000-00494000 r-xp 00000000 08:05 150971                             /home/max/Documents/c++proj/voip/build/testclient
  85. 00693000-00694000 r--p 00093000 08:05 150971                             /home/max/Documents/c++proj/voip/build/testclient
  86. 00694000-00695000 rw-p 00094000 08:05 150971                             /home/max/Documents/c++proj/voip/build/testclient
  87. 00695000-00696000 rw-p 00000000 00:00 0
  88. 04000000-04020000 r-xp 00000000 08:05 560792                             /lib/ld-2.12.1.so
  89. 04020000-04022000 rw-p 00000000 00:00 0
  90. 0403f000-04045000 rw-p 00000000 00:00 0
  91. 04220000-04221000 r--p 00020000 08:05 560792                             /lib/ld-2.12.1.so
  92. 04221000-04222000 rw-p 00021000 08:05 560792                             /lib/ld-2.12.1.so
  93. 04222000-04223000 rw-p 00000000 00:00 0
  94. 04223000-04224000 rwxp 00000000 00:00 0
  95. 04a23000-04a24000 r-xp 00000000 08:05 145700                             /usr/lib/valgrind/vgpreload_core-amd64-linux.so
  96. 04a24000-04c23000 ---p 00001000 08:05 145700                             /usr/lib/valgrind/vgpreload_core-amd64-linux.so
  97. 04c23000-04c24000 r--p 00000000 08:05 145700                             /usr/lib/valgrind/vgpreload_core-amd64-linux.so
  98. 04c24000-04c25000 rw-p 00001000 08:05 145700                             /usr/lib/valgrind/vgpreload_core-amd64-linux.so
  99. 04c25000-04c2d000 r-xp 00000000 08:05 145715                             /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  100. 04c2d000-04e2c000 ---p 00008000 08:05 145715                             /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  101. 04e2c000-04e2d000 r--p 00007000 08:05 145715                             /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  102. 04e2d000-04e2e000 rw-p 00008000 08:05 145715                             /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
  103. 04e2e000-04e46000 r-xp 00000000 08:05 557639                             /lib/libpthread-2.12.1.so
  104. 04e46000-05045000 ---p 00018000 08:05 557639                             /lib/libpthread-2.12.1.so
  105. 05045000-05046000 r--p 00017000 08:05 557639                             /lib/libpthread-2.12.1.so
  106. 05046000-05047000 rw-p 00018000 08:05 557639                             /lib/libpthread-2.12.1.so
  107. 05047000-0504b000 rw-p 00000000 00:00 0
  108. 0504b000-05133000 r-xp 00000000 08:05 656172                             /usr/lib/libstdc++.so.6.0.14
  109. 05133000-05332000 ---p 000e8000 08:05 656172                             /usr/lib/libstdc++.so.6.0.14
  110. 05332000-0533a000 r--p 000e7000 08:05 656172                             /usr/lib/libstdc++.so.6.0.14
  111. 0533a000-0533c000 rw-p 000ef000 08:05 656172                             /usr/lib/libstdc++.so.6.0.14
  112. 0533c000-05351000 rw-p 00000000 00:00 0
  113. 05351000-053d3000 r-xp 00000000 08:05 560787                             /lib/libm-2.12.1.so
  114. 053d3000-055d2000 ---p 00082000 08:05 560787                             /lib/libm-2.12.1.so
  115. 055d2000-055d3000 r--p 00081000 08:05 560787                             /lib/libm-2.12.1.so
  116. 055d3000-055d4000 rw-p 00082000 08:05 560787                             /lib/libm-2.12.1.so
  117. 055d4000-055e9000 r-xp 00000000 08:05 521495                             /lib/libgcc_s.so.1
  118. 055e9000-057e8000 ---p 00015000 08:05 521495                             /lib/libgcc_s.so.1
  119. 057e8000-057e9000 r--p 00014000 08:05 521495                             /lib/libgcc_s.so.1
  120. 057e9000-057ea000 rw-p 00015000 08:05 521495                             /lib/libgcc_s.so.1
  121. 057ea000-05964000 r-xp 00000000 08:05 557476                             /lib/libc-2.12.1.so
  122. 05964000-05b63000 ---p 0017a000 08:05 557476                             /lib/libc-2.12.1.so
  123. 05b63000-05b67000 r--p 00179000 08:05 557476                             /lib/libc-2.12.1.so
  124. 05b67000-05b68000 rw-p 0017d000 08:05 557476                             /lib/libc-2.12.1.so
  125. 05b68000-05b6d000 rw-p 00000000 00:00 0
  126. 05b6d000-05f6d000 rwxp 00000000 00:00 0
  127. 05f6d000-05f6e000 ---p 00000000 00:00 0
  128. 05f6e000-0676e000 rw-p 00000000 00:00 0
  129. 0676e000-0676f000 ---p 00000000 00:00 0
  130. 0676f000-06f6f000 rw-p 00000000 00:00 0
  131. 06f6f000-06f70000 ---p 00000000 00:00 0
  132. 06f70000-07770000 rw-p 00000000 00:00 0
  133. 07770000-07771000 ---p 00000000 00:00 0
  134. 07771000-07f71000 rw-p 00000000 00:00 0
  135. 38000000-381fc000 r-xp 00200000 08:05 145710                             /usr/lib/valgrind/memcheck-amd64-linux
  136. 383fb000-383fe000 rw-p 003fb000 08:05 145710                             /usr/lib/valgrind/memcheck-amd64-linux
  137. 383fe000-3927e000 rw-p 00000000 00:00 0
  138. 402001000-403272000 rwxp 00000000 00:00 0
  139. 403272000-403274000 ---p 00000000 00:00 0
  140. 403274000-403374000 rwxp 00000000 00:00 0
  141. 403374000-403376000 ---p 00000000 00:00 0
  142. 403376000-40583e000 rwxp 00000000 00:00 0
  143. 40583e000-405840000 ---p 00000000 00:00 0
  144. 405840000-405940000 rwxp 00000000 00:00 0
  145. 405940000-405942000 ---p 00000000 00:00 0
  146. 405942000-405946000 rwxp 00000000 00:00 0
  147. 405946000-405948000 ---p 00000000 00:00 0
  148. 405948000-405a48000 rwxp 00000000 00:00 0
  149. 405a48000-405a4a000 ---p 00000000 00:00 0
  150. 405a4a000-405a4e000 rwxp 00000000 00:00 0
  151. 405a4e000-405a50000 ---p 00000000 00:00 0
  152. 405a50000-405b50000 rwxp 00000000 00:00 0
  153. 405b50000-405b52000 ---p 00000000 00:00 0
  154. 405b52000-405b5a000 rwxp 00000000 00:00 0
  155. 405b5a000-405b5c000 ---p 00000000 00:00 0
  156. 405b5c000-405c5c000 rwxp 00000000 00:00 0
  157. 405c5c000-405c5e000 ---p 00000000 00:00 0
  158. 405c5e000-405c62000 rwxp 00000000 00:00 0
  159. 7feffd000-7ff001000 rwxp 00000000 00:00 0
  160. 7fffb9f36000-7fffb9f57000 rw-p 00000000 00:00 0                          [stack]
  161. ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement