Browse Source

Widen report line buffer & overrun trap

I'm seeing 100+chr domain names and really long lists of ports, that
overflowed the 256 byte buffer, causing the LFs to fall off. This change
will throw an exception if the buffer is too short again. But I pushed
it up to 1024 (4x). Seriously long host names?
master
Jon Foster 8 months ago
parent
commit
6756bb0087
1 changed files with 4 additions and 3 deletions
  1. +4
    -3
      trafficmon/badtrafficrpt.cpp

+ 4
- 3
trafficmon/badtrafficrpt.cpp View File

@@ -80,7 +80,7 @@ struct ReportData: map<string,ReportLine> {
string ascii() const {
int widths[3] = {0,0,0}; // max column widths: 0: DNS, 1: ports, 3: counts
int x;
char l[256]; l[255]=0;
char l[1024]; l[1023]=0;
string s, r, bk;
ReportData::const_iterator it;

@@ -90,7 +90,7 @@ struct ReportData: map<string,ReportLine> {
if(s.size()>widths[1]) widths[1]=s.size();
if(it->second.count>widths[2]) widths[2] = it->second.count;
}
// Now conver count max to cols
// Now convert count max to cols
for(x=0; widths[2]; x++) widths[2] /= 10;
widths[2] = x ? x : 1;
// min col widths for titles
@@ -103,6 +103,8 @@ struct ReportData: map<string,ReportLine> {
"+"+string(widths[1]+2, '-')+
"+"+string(widths[2]+2, '-')+
"+\n";
if(bk.size()>=sizeof(l)-1) throw std::runtime_error(
"ReportData::ascii: report row width is too long.");
s = "| %-"+str(widths[0])+"s | %-"+str(widths[1])+"s | %"+str(widths[2])+"d |\n";
r = bk;
snprintf(l, sizeof(l)-1,
@@ -227,6 +229,5 @@ namespace cppdb {
if(rec.name=="") rec.name=rec.them;
rpt.add(rec.name, str(rec.them_port), ct);
}
else cerr << "ignored" << endl;
}
}

Loading…
Cancel
Save