I am using boost::asio::async_read_until to read a message from a socket, using a newline as a delimiter.
eg boost::asio::async_read_until(socket, buffer, "\\n", .....)
Everything is hunkey dorey and works fine.
Is there an alternative way to use this function, or a similar one, that can detect an endless sequence of characters that do not have a newline constant in them.
eg a malicious user might fire a continuous sequence of ZEROS at my server
I can't be the first person in history to have come across this problem
You can use version 4 of the 4 overloads:
http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/reference/async_read_until/overload4.html
In your function object, which would normally be an interface to a state machine, you can count characters, detect illegal data streams or any other means necessary.
It's probably worth mentioning that if your application is running in a hostile environment (ie internet-facing) then you will probably want to use async_read_some
to feed your state machine and will want a timer to catch and kill connections that sit and consume resources.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.