aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-12-29 21:46:03 +0000
committerMike Buland <eichlan@xagasoft.com>2008-12-29 21:46:03 +0000
commit1743bd0eacec94c6f6e3c89e16d0bd6d301017e8 (patch)
treea4de5c4bf9ebb8b9181daa8ec52c697dc3e1ff63
parentf461b3c1839e5cfc85685ed1cb828ecaa74d6912 (diff)
downloadlibbu++-1743bd0eacec94c6f6e3c89e16d0bd6d301017e8.tar.gz
libbu++-1743bd0eacec94c6f6e3c89e16d0bd6d301017e8.tar.bz2
libbu++-1743bd0eacec94c6f6e3c89e16d0bd6d301017e8.tar.xz
libbu++-1743bd0eacec94c6f6e3c89e16d0bd6d301017e8.zip
Corrected the premature end of stream read corner case in Taf...it was freaking
out and allocating all memory, now it just throws an exception.
-rw-r--r--src/tafreader.cpp23
-rw-r--r--src/tafreader.h1
-rw-r--r--src/unit/taf.cpp16
3 files changed, 37 insertions, 3 deletions
diff --git a/src/tafreader.cpp b/src/tafreader.cpp
index 7bb0933..4408cce 100644
--- a/src/tafreader.cpp
+++ b/src/tafreader.cpp
@@ -209,15 +209,32 @@ void Bu::TafReader::next()
209 iCol++; 209 iCol++;
210 if( c == '}' ) 210 if( c == '}' )
211 { 211 {
212 sIn.read( &c, 1 ); 212 rawread( &c );
213 if( c != '}' ) 213 if( c != '}' )
214 sIn.read( &la, 1 ); 214 rawread( &la );
215 } 215 }
216 else 216 else
217 { 217 {
218 c = la; 218 c = la;
219 if( c != '}' ) 219 if( c != '}' )
220 sIn.read( &la, 1 ); 220 rawread( &la );
221 }
222}
223
224void Bu::TafReader::rawread( char *c )
225{
226 if( sIn.read( c, 1 ) < 1 )
227 {
228 if( sIn.isEOS() )
229 {
230 throw TafException("%d:%d: Premature end of stream.",
231 iLine, iCol, c );
232 }
233 else
234 {
235 throw TafException("%d:%d: No data read, but not end of stream?",
236 iLine, iCol, c );
237 }
221 } 238 }
222} 239}
223 240
diff --git a/src/tafreader.h b/src/tafreader.h
index ce67a5f..53ab6d4 100644
--- a/src/tafreader.h
+++ b/src/tafreader.h
@@ -35,6 +35,7 @@ namespace Bu
35 bool isws(); 35 bool isws();
36 void next(); 36 void next();
37 Bu::FString readStr(); 37 Bu::FString readStr();
38 void rawread( char *c );
38 char c, la; 39 char c, la;
39 Bu::Stream &sIn; 40 Bu::Stream &sIn;
40 int iLine, iCol; 41 int iLine, iCol;
diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp
index 3bf7cc6..e4b3ccc 100644
--- a/src/unit/taf.cpp
+++ b/src/unit/taf.cpp
@@ -23,6 +23,7 @@ public:
23 addTest( Unit::read1 ); 23 addTest( Unit::read1 );
24 addTest( Unit::encode1 ); 24 addTest( Unit::encode1 );
25 addTest( Unit::emptyStr1 ); 25 addTest( Unit::emptyStr1 );
26 addTest( Unit::incomplete1 );
26 } 27 }
27 28
28 virtual ~Unit() 29 virtual ~Unit()
@@ -108,6 +109,21 @@ public:
108 unitTest( 109 unitTest(
109 mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); 110 mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" );
110 } 111 }
112
113 void incomplete1()
114 {
115 try
116 {
117 Bu::MemBuf mb("{Lame: \"Hello=\"");
118 Bu::TafReader tr( mb );
119 delete tr.readGroup();
120 unitFailed("Should have thrown an exception, didn't.");
121 }
122 catch( Bu::TafException &e )
123 {
124 // Woot
125 }
126 }
111}; 127};
112 128
113int main( int argc, char *argv[] ) 129int main( int argc, char *argv[] )