Change m_str.replace back to insert + remove StringStream limit

pull/40/head
Vitaliy Filippov 2015-10-10 13:00:54 +03:00
parent 887da88c14
commit df99954382
2 changed files with 2 additions and 16 deletions

View File

@ -23,13 +23,6 @@
namespace gr { namespace gr {
namespace
{
// the max size of the cached string. this is to prevent allocating
// too much memory if client sends a line too long (i.e. DOS attack)
const std::size_t capacity = 4096 ;
}
StringStream::StringStream( const std::string& init ) : StringStream::StringStream( const std::string& init ) :
// FIXME avoid copy // FIXME avoid copy
m_str( init ), m_pos( 0 ) m_str( init ), m_pos( 0 )
@ -48,10 +41,8 @@ std::size_t StringStream::Read( char *data, std::size_t size )
std::size_t StringStream::Write( const char *data, std::size_t size ) std::size_t StringStream::Write( const char *data, std::size_t size )
{ {
std::size_t count = std::min( size, capacity - m_str.size() ) ; m_str.insert( m_str.size(), data, size ) ;
m_str.replace( m_str.begin() + m_pos, m_str.begin() + m_pos + count, data, data+count ) ; return size ;
m_pos += count ;
return count ;
} }
off_t StringStream::Seek( off_t offset, int whence ) off_t StringStream::Seek( off_t offset, int whence )

View File

@ -30,11 +30,6 @@ namespace gr {
StringStream is a DataStream back-end that uses std::string for storage. StringStream is a DataStream back-end that uses std::string for storage.
It is useful for unit tests and text parsing, especially when used with It is useful for unit tests and text parsing, especially when used with
StreamParser. StreamParser.
StringStream has a limit on the maximum number of byte it stores. This
is to prevent DOS attacks in which the client sends a lot of bytes before
the delimiter (e.g. new-line characters) and the server is forced to hold
all of them in memory.
*/ */
class StringStream : public SeekStream class StringStream : public SeekStream
{ {