Ticket #6701: pool.patch

File pool.patch, 1.1 KB (added by Xi Wang <xi.wang@…>, 11 years ago)

fix integer overflows in pool::ordered_malloc

  • boost/pool/pool.hpp

     
    1010#define BOOST_POOL_HPP
    1111
    1212#include <boost/config.hpp>  // for workarounds
     13// std::numeric_limits
     14#include <boost/limits.hpp>
    1315
    1416// std::less, std::less_equal, std::greater
    1517#include <functional>
     
    793795  //! \returns Address of chunk n if allocated ok.
    794796  //! \returns 0 if not enough memory for n chunks.
    795797
     798  if (requested_size && (n > (std::numeric_limits<size_type>::max)() / requested_size))
     799    return 0;
    796800  const size_type partition_size = alloc_size();
    797801  const size_type total_req_size = n * requested_size;
    798802  const size_type num_chunks = total_req_size / partition_size +
     
    975979  {
    976980     if(max_alloc_size && (n > max_alloc_size))
    977981        return 0;
     982     if(chunk_size && (n > (std::numeric_limits<size_type>::max)() / chunk_size))
     983        return 0;
    978984     void* ret = (user_allocator::malloc)(chunk_size * n);
    979985     used_list.insert(ret);
    980986     return ret;