Skip to content

Commit 535f93c

Browse files
author
dlitty1
committed
added logic to prevent infinite loop on a stream read failure, as well as accomodating long lines in the ripe file
1 parent 7acbdc6 commit 535f93c

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

parser.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ int main() {
5656

5757
// read the Parsed delegation files to set, the set sorts the entries based on ipFrom then on ipTo
5858
while ( !(inDel.getline(cBuf,LINE_LENGTH).eof()) ) {
59+
if ( inDel.fail() )
60+
{
61+
cout << "Error reading Testout file" << std::endl;
62+
return 1;
63+
}
5964
sStr = cBuf;
6065
if ( !sStr.empty() ) {
6166
DBRangeEntries entry;
@@ -209,6 +214,11 @@ int main() {
209214

210215
// read the final version of the delegation files to sort it.
211216
while ( !(inDB.getline(cBuf,LINE_LENGTH).eof()) ) {
217+
if ( inDB.fail() )
218+
{
219+
cout << "Error reading DBout file" << std::endl;
220+
return 1;
221+
}
212222
sStr = cBuf;
213223
if ( !sStr.empty() ) {
214224
DBEntries entry;
@@ -311,6 +321,11 @@ void dbParser( string dbIn , string delName, string dbOut ) {
311321
// "inetnum: 202.14.104.0 - 202.14.104.255"
312322
// "country: AU"
313323
while ( !(inDB.getline(cBuf,LINE_LENGTH).eof()) ) {
324+
if ( inDB.fail() )
325+
{
326+
cout << "Error reading " << dbIn << " file" << std::endl;
327+
exit(1);
328+
}
314329
sStr = cBuf;
315330
if ( sStr.empty() ) {
316331
bTrigger = true;
@@ -364,6 +379,11 @@ void dbParser( string dbIn , string delName, string dbOut ) {
364379
set < DBEntries , compare_entries > seStructEntries;
365380

366381
while ( !(in.getline(cBuf,LINE_LENGTH).eof()) ) {
382+
if ( in.fail() )
383+
{
384+
cout << "Error reading " << s.c_str() << " file" << std::endl;
385+
exit(1);
386+
}
367387
sEntry.clear();
368388
sStr = cBuf;
369389
if( !sStr.empty() ) {
@@ -618,6 +638,11 @@ void delegParser( string delName, string delegOut ) {
618638
ofstream outDB ((findValue(delegOut)).c_str(), ios::app);
619639

620640
while ( !(in.getline(cBuf,LINE_LENGTH).eof()) ) {
641+
if ( in.fail() )
642+
{
643+
cout << "Error reading " << delName.c_str() << " file" << std::endl;
644+
exit(1);
645+
}
621646
sEntry.clear();
622647
sIPFrom.clear();
623648
sStr = cBuf;

parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838

3939
using namespace std;
40-
#define LINE_LENGTH 600
40+
#define LINE_LENGTH 2048
4141

4242
void dbParser( string dbIn , string delName, string dbOut );
4343
void delegParser( string , string );

0 commit comments

Comments
 (0)