[Botan-devel] [PATCH] Use ios::binary on streams that are expected to be binary

Matthew Gregan kinetik at orcon.net.nz
Mon Nov 28 17:25:10 EST 2005


Hello,

I submitted this patch a few months back, but didn't hear anything.  I'm not
sure if that was because it's totally bogus and nobody said anything to save
me the embarassment, or what... but I'm posting it again to get some
feedback. :-)

There are a few places in Botan that read from C++ fstreams and appear to
assume the stream is binary clean, but don't open the stream explicitly as
binary.  This patch fixes that issue.

We've had this patch applied to a local copy of Botan in monotone for a few
releases now--it solved the problems we ran into, and we haven't seen any
problematic behaviour caused by it.  If the patch isn't totally bogus, it'd
be nice to have it applied upstream to reduce the delta between Botan
releases and what we have in our tree.

Thanks,
-mjg
-- 
Matthew Gregan                     |/
                                  /|                kinetik at orcon.net.nz
-------------- next part --------------
diff -BNru Botan-1.4.9/modules/es_ftw/es_ftw.cpp Botan-1.4.9-bin/modules/es_ftw/es_ftw.cpp
--- Botan-1.4.9/modules/es_ftw/es_ftw.cpp	2005-03-14 13:31:05.000000000 +1300
+++ Botan-1.4.9-bin/modules/es_ftw/es_ftw.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -88,7 +88,7 @@
 *************************************************/
 void FTW_EntropySource::gather_from_file(const std::string& filename)
    {
-   std::ifstream in(filename.c_str());
+   std::ifstream in(filename.c_str(), std::ios::binary);
    if(!in) return;
 
    SecureVector<byte> read_buf(1024);
diff -BNru Botan-1.4.9/src/data_snk.cpp Botan-1.4.9-bin/src/data_snk.cpp
--- Botan-1.4.9/src/data_snk.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.9-bin/src/data_snk.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -32,7 +32,7 @@
 *************************************************/
 DataSink_Stream::DataSink_Stream(const std::string& file) : fsname(file)
    {
-   sink = new std::ofstream(fsname.c_str());
+   sink = new std::ofstream(fsname.c_str(), std::ios::binary);
    if(!sink->good())
       throw Stream_IO_Error("DataSink_Stream: Failure opening " + fsname);
    owns = true;
diff -BNru Botan-1.4.9/src/data_src.cpp Botan-1.4.9-bin/src/data_src.cpp
--- Botan-1.4.9/src/data_src.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.9-bin/src/data_src.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -156,7 +156,7 @@
 *************************************************/
 DataSource_Stream::DataSource_Stream(const std::string& file) : fsname(file)
    {
-   source = new std::ifstream(fsname.c_str());
+   source = new std::ifstream(fsname.c_str(), std::ios::binary);
    if(!source->good())
       throw Stream_IO_Error("DataSource_Stream: Failure opening " + fsname);
    total_read = 0;
diff -BNru Botan-1.4.9/src/es_file.cpp Botan-1.4.9-bin/src/es_file.cpp
--- Botan-1.4.9/src/es_file.cpp	2005-03-14 13:31:04.000000000 +1300
+++ Botan-1.4.9-bin/src/es_file.cpp	2005-08-07 18:56:40.000000000 +1200
@@ -39,7 +39,7 @@
    u32bit read = 0;
    for(u32bit j = 0; j != sources.size(); j++)
       {
-      std::ifstream random_source(sources[j].c_str());
+      std::ifstream random_source(sources[j].c_str(), std::ios::binary);
       if(!random_source) continue;
       random_source.read((char*)output + read, length);
       read += random_source.gcount();


More information about the botan-devel mailing list