Re: changing streambuf to address a security hole
JSprenkle ha scritto:
I'd like to address a security hole in my application. Through a
number of techniques it's possible to obtain a RAM dump of a running
application. I'm using stringstream's to do type conversions. To
minimize the amount of information left lying around in RAM I'd like
to clear the streambuf used by these routines before it's delete'd.
Is anyone willing to provide a little help? (I'd like to do a version
for MSVC and GCC)
My research has so far left me very unhappy and frustrated. I have
what should be a simple
requirement and it's been extremely difficult to implement. The 'big
brains' claim streams
code is one of the finest examples of c++. The claim for c++ and
Although I like and respect the iostream library and I think it's a good
piece of software, I wouldn't say that it's "one of the finest examples
of c++". (I'm no "big brain" so take my words for what their worth).
object orientation are that
inheritance allows us to change behaviours of base classes. Except
with c++ you can't use
inheritance with streams (or STL). Seems like somebody missed some
fundamentals
along the way.
I don't understand your statement. You *can* use inheritance to change
the behaviour of stream classes. You just need to target the right class
;) The class you want to derive from is streambuf, which has a whole
bunch of virtual functions that you can implement with your customized
behaviour. Once you have your desired behaviour in a streambuf class,
just attach it to a stream class with function rdbuf().
Writing your own streambuf class is not an easy task. For some examples
you can have a look at the Boost.Iostream library. I also had written a
very simple implementation of a streambuf in paper:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2065.pdf
my membuf addresses a very specific issue (user-provided fixed memory
buffer), so it's not easily generalizable to dynamic-sized streams.
However, dynamic-sized streams are bad for security because they may
need to reallocate their internal buffers multiple times during their
lifetime, leaving copies of your sensitive data all around the memory
which can be difficult to track down.
If you can estimate the maximum size of your buffers, I claim my
memstream is the perfect solution for you. (Actually I might add
"improved security" as an additional rationale in my paper ;)
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]