Re: Preventing Denial of Service Attack In IPC Serialization
firstname.lastname@example.org (Jeff Koftinoff) wrote (abridged):
Most definitely, the 'std::string code' member of the stocks
structure ought to have a small limit
Although that does no harm, I don't think it helps for some items to have
small limits if other items have big limits. Hackers can focus on the
items with big limits.
In your example, the sizeof(T) does not include the size of each
individual stock 'code' and stock 'name' strings
It doesn't need to. It only has to worry about its own allocations, not
allocations done elsewhere. Each object looks after itself, and the
socket looks after the total.
This may mean we allocate capacity for 10,000 (then zero-length) strings,
and that the memory budget is exceeded in the middle of trying to
actually deserialise them (to greater than zero length). So be it. The
socket tracks the total bytes deserialised, diagnoses a DoS attack,
throws an exception, the stack unwinds, the memory is reclaimed, the
attack is foiled. Life goes on.
-- Dave Harris, Nottingham, UK.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]