From 92348cd85a8377119954d069a7140717b1f0db07 Mon Sep 17 00:00:00 2001 From: arjen Date: Wed, 14 Nov 2007 16:19:25 +0000 Subject: [PATCH] Bugfix: Segmentation fault when reading an rpm package list with empty lines. --- src/gcm_input/gcm_input.cpp | 11 +++++--- src/gcm_input/rpm_filter.cpp | 66 +++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/gcm_input/gcm_input.cpp b/src/gcm_input/gcm_input.cpp index bcce2e8..4717f22 100644 --- a/src/gcm_input/gcm_input.cpp +++ b/src/gcm_input/gcm_input.cpp @@ -7,7 +7,7 @@ *********************** ** FILE NAME : gcm_input.cpp ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring -** VERSION NUMBER : $Revision: 1.14 $ +** VERSION NUMBER : $Revision: 1.15 $ ** ** DESCRIPTION : Application to store client messages into the database ** The client message contains a log file from one of the @@ -54,7 +54,11 @@ /***************************** $Log: gcm_input.cpp,v $ - Revision 1.14 2007-11-03 10:26:13 arjen + Revision 1.15 2007-11-14 16:19:25 arjen + Bugfix: Segmentation fault when reading an rpm package list + with empty lines. + + Revision 1.14 2007/11/03 10:26:13 arjen Added a new filter which can directly read the output of the UNIX df command. A brief description is added in the user manual. @@ -118,7 +122,7 @@ *****************************/ -static const char *RCSID = "$Id: gcm_input.cpp,v 1.14 2007-11-03 10:26:13 arjen Exp $"; +static const char *RCSID = "$Id: gcm_input.cpp,v 1.15 2007-11-14 16:19:25 arjen Exp $"; #include @@ -302,7 +306,6 @@ int main(int argc, char *argv[]) msg.add_cooker(&dlc, &df); message_probability = msg.classify(hostname, arrival, service); - *Log << "Message type probability = " << message_probability << "\n"; if (message_probability > 0.75) { try diff --git a/src/gcm_input/rpm_filter.cpp b/src/gcm_input/rpm_filter.cpp index dd8655d..98669bd 100644 --- a/src/gcm_input/rpm_filter.cpp +++ b/src/gcm_input/rpm_filter.cpp @@ -8,7 +8,7 @@ *********************** ** FILE NAME : rpm_filter.cpp ** SYSTEM NAME : -** VERSION NUMBER : $Revision: 1.1 $ +** VERSION NUMBER : $Revision: 1.2 $ ** ** DESCRIPTION : Transform a list of packages into a Gnucomo XML document ** @@ -20,13 +20,17 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Nov 27, 2003 -** LAST UPDATE : Nov 27, 2003 +** LAST UPDATE : Nov 12, 2007 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: rpm_filter.cpp,v $ - Revision 1.1 2003-12-04 10:38:09 arjen + Revision 1.2 2007-11-14 16:19:25 arjen + Bugfix: Segmentation fault when reading an rpm package list + with empty lines. + + Revision 1.1 2003/12/04 10:38:09 arjen Major redesign. All input is handled through XML. Raw input data is first transformed into an XML document for further processing. A collection of polymorphic classes handle the transformation of various @@ -35,7 +39,7 @@ *****************************/ -/* static const char *RCSID = "$Id: rpm_filter.cpp,v 1.1 2003-12-04 10:38:09 arjen Exp $"; */ +/* static const char *RCSID = "$Id: rpm_filter.cpp,v 1.2 2007-11-14 16:19:25 arjen Exp $"; */ #include @@ -64,10 +68,12 @@ ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : Nov 27, 2003 +** LAST MODIFIED : Nov 12, 2007 **========================================================================= */ +static const regex re_rpm("[[:alnum:]+-]+-[0-9][[:alnum:].-]"); + void rpm_filter::construct_XML(message_buffer &in, std::strstream &xml) { String line; @@ -83,46 +89,48 @@ void rpm_filter::construct_XML(message_buffer &in, std::strstream &xml) int version_start, next_version_start; int i; - // Separate the package name from the version number + if (line == re_rpm) + { + // Separate the package name from the version number - i = line.index('-'); - version_start = i; - next_version_start = i; + i = line.index('-'); - while (i < ~line - 1) - { - while (i < ~line - 1 && !(line[i] == '-' && isdigit(line[i + 1]))) + version_start = i; + next_version_start = i; + + while (i < ~line - 1) { + while (i < ~line - 1 && !(line[i] == '-' && isdigit(line[i + 1]))) + { + i++; + } + if (i < ~line - 1) + { + version_start = next_version_start; + next_version_start = i; + } i++; } - if (i < ~line - 1) + + if (!isdigit(line[version_start + 1])) { version_start = next_version_start; - next_version_start = i; } - i++; - } - - if (!isdigit(line[version_start + 1])) - { - version_start = next_version_start; - } - String package(line(0,version_start)); - String version(line(version_start + 1, ~line)); + String package(line(0,version_start)); + String version(line(version_start + 1, ~line)); - // Create the XML element. + // Create the XML element. - xml << " \n"; - xml << " " << version << "\n"; - xml << " \n"; + xml << " \n"; + xml << " " << version << "\n"; + xml << " \n"; + } } xml << " \n"; xml << " \n"; xml << "\n"; } -static const regex re_rpm("[[:alnum:]+-]+-[0-9][[:alnum:].-]"); - bool rpm_cooker::check_pattern(String logline) { return logline == re_rpm; -- 2.11.0