From 6756bb0087bf418f69d5eec61f7326c21da0c182 Mon Sep 17 00:00:00 2001 From: Jon Foster Date: Fri, 22 Mar 2024 10:02:38 -0700 Subject: [PATCH] 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? --- trafficmon/badtrafficrpt.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/trafficmon/badtrafficrpt.cpp b/trafficmon/badtrafficrpt.cpp index 1f7a157..aa72696 100644 --- a/trafficmon/badtrafficrpt.cpp +++ b/trafficmon/badtrafficrpt.cpp @@ -80,7 +80,7 @@ struct ReportData: map { 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 { 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(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; } }