Browse Source

Replaced all assert() with appropriate Checks and Faults in SNFMulti and it's components. Also added some minor tweaks to improve code safety and eliminate compiler warnings.

git-svn-id: https://svn.microneil.com/svn/SNFMulti/trunk@15 dc71a809-1921-45c4-985c-09c81d0142d9
wx
madscientist 15 years ago
parent
commit
a457509f6a
7 changed files with 32 additions and 14 deletions
  1. 4
    2
      GBUdb.cpp
  2. 1
    0
      GBUdb.hpp
  3. 19
    8
      SNFMulti.cpp
  4. 2
    1
      SNFMulti.hpp
  5. 1
    1
      snfXCImgr.cpp
  6. 3
    1
      snf_engine.cpp
  7. 2
    1
      snf_engine.hpp

+ 4
- 2
GBUdb.cpp View File

rename(TempFileName.c_str(), MyFileName.c_str()); // Then make our new file current. rename(TempFileName.c_str(), MyFileName.c_str()); // Then make our new file current.
} }
} }
const RuntimeCheck SaneFileSizeCheck("GBUdbDataset::load():SaneFileSizeCheck(SaneGBUdbFileSizeLimit <= FileSize)");


void GBUdbDataset::load() { // Read the GBUdb from disk. void GBUdbDataset::load() { // Read the GBUdb from disk.


dbFile.seekg(0, ios::beg); // determine it's size. dbFile.seekg(0, ios::beg); // determine it's size.


int SaneGBUdbFileSizeLimit = (GBUdbDefaultArraySize * sizeof(GBUdbRecord)); // What is a sane size limit? int SaneGBUdbFileSizeLimit = (GBUdbDefaultArraySize * sizeof(GBUdbRecord)); // What is a sane size limit?
assert(SaneGBUdbFileSizeLimit <= FileSize); // File size sanity check.
SaneFileSizeCheck(SaneGBUdbFileSizeLimit <= FileSize); // File size sanity check.


int NewArraySize = FileSize / sizeof(GBUdbRecord); // How many records in this file? int NewArraySize = FileSize / sizeof(GBUdbRecord); // How many records in this file?


string GBUdbAlert::toXML() { // Convert this alert to XML text string GBUdbAlert::toXML() { // Convert this alert to XML text
stringstream Alert; // We'll use a stringstream. stringstream Alert; // We'll use a stringstream.


const char* FlagName; // We will want the Flag as text.
const char* FlagName = "ERROR"; // We will want the Flag as text.
switch(R.Flag()) { // Switch on the Flag() value. switch(R.Flag()) { // Switch on the Flag() value.
case Good: { FlagName = "Good"; break; } // Convert each value to it's name. case Good: { FlagName = "Good"; break; } // Convert each value to it's name.
case Bad: { FlagName = "Bad"; break; } case Bad: { FlagName = "Bad"; break; }

+ 1
- 0
GBUdb.hpp View File

#ifndef M_GBUdb #ifndef M_GBUdb
#define M_GBUdb #define M_GBUdb


#include "../CodeDweller/faults.hpp"
#include "../CodeDweller/threading.hpp" #include "../CodeDweller/threading.hpp"
#include <cmath> #include <cmath>
#include <cctype> #include <cctype>

+ 19
- 8
SNFMulti.cpp View File



//// Version Info //// Version Info


const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.1 Build: " __DATE__ " " __TIME__;
const char* SNF_ENGINE_VERSION = "SNFMulti Engine Version 3.0.5 Build: " __DATE__ " " __TIME__;


//// Script Caller Methods //// Script Caller Methods


// done it will reset from the "RefreshInProgress" state and along the way will throw any errors that // done it will reset from the "RefreshInProgress" state and along the way will throw any errors that
// are appropriate. The other functions can count on this one to polish off the various forms of rulebase // are appropriate. The other functions can count on this one to polish off the various forms of rulebase
// load activity. // load activity.
const LogicCheck SaneRefreshProcessCheck("snf_RulebaseHandler::_snf_LoadNewRulebase():SaneRefreshProcessCheck(RefreshInProgress)");


void snf_RulebaseHandler::_snf_LoadNewRulebase(){ // Common internal load/check routine. void snf_RulebaseHandler::_snf_LoadNewRulebase(){ // Common internal load/check routine.
assert(RefreshInProgress); // We only get called when this flag is set.
SaneRefreshProcessCheck(RefreshInProgress); // We only get called when this flag is set.
try { MyCFGmgr.load(); } // Load a fresh copy of the configuration. try { MyCFGmgr.load(); } // Load a fresh copy of the configuration.
catch(...) { // If something goes wrong: catch(...) { // If something goes wrong:
RefreshInProgress = false; // we are no longer "in refresh" RefreshInProgress = false; // we are no longer "in refresh"


return ExtractedID; // Return the extracted id or substitute. return ExtractedID; // Return the extracted id or substitute.
} }
const LogicFault FaultBadMessageBuffer1("snf_EngineHandler::scanMessage():FaultBadMessageBuffer1(NULL == inputMessageBuffer)");
const LogicFault FaultBadMessageBuffer2("snf_EngineHandler::scanMessage():FaultBadMessageBuffer2(0 >= inputMessageLength)");


int snf_EngineHandler::scanMessage( // Scan this message (in buffer). int snf_EngineHandler::scanMessage( // Scan this message (in buffer).
const unsigned char* inputMessageBuffer, // -- this is the message buffer. const unsigned char* inputMessageBuffer, // -- this is the message buffer.
const IP4Address MessageSource // -- message source IP (for injection). const IP4Address MessageSource // -- message source IP (for injection).
) { ) {


// Protect this code - only one thread at a time per EngineHandler ;-)
ScopeTimer ScanTimeCapture(MyScanData.ScanTime); // Start the scan time clock.
unsigned char* MessageBuffer = NULL; // Explicitly initialize these two
int MessageLength = 0; // so the compiler will be happy.
FaultBadMessageBuffer1(NULL == inputMessageBuffer); // Fault on null message buffer.
FaultBadMessageBuffer2(0 >= inputMessageLength); // Fault on bad message bfr length.
// Protect this engine - only one scan at a time per EngineHandler ;-)


ScopeTimer ScanTimeCapture(MyScanData.ScanTime); // Start the scan time clock.
ScopeMutex ScannerIsBusy(MyMutex); // Serialize this... ScopeMutex ScannerIsBusy(MyMutex); // Serialize this...


// Preliminary job setup. // Preliminary job setup.
// originals and then use the captured values. For example if we are scanning // originals and then use the captured values. For example if we are scanning
// Communigate message files we will want to skip the communigate headers. // Communigate message files we will want to skip the communigate headers.


unsigned char* MessageBuffer =
const_cast<unsigned char*>(inputMessageBuffer); // Capture the input buffer.
int MessageLength = inputMessageLength; // Capture the input length.
MessageBuffer = const_cast<unsigned char*>(inputMessageBuffer); // Capture the input buffer.
MessageLength = inputMessageLength; // Capture the input length.


MyScanData.clear(); // Clear the scan data. MyScanData.clear(); // Clear the scan data.
MyScanData.ScanSize = MessageLength; // Grab the message length. MyScanData.ScanSize = MessageLength; // Grab the message length.


// To integrate GBUdb we need to generalize the result from the pattern scan. // To integrate GBUdb we need to generalize the result from the pattern scan.


PatternResultTypes ScanResultType; // What kind of result have we here?
PatternResultTypes ScanResultType = NoPattern; // What kind of result have we here?
if(0 < (MyScanData.HeaderDirectiveFlags & HeaderDirectiveWhite)) { // If a white header directive matched if(0 < (MyScanData.HeaderDirectiveFlags & HeaderDirectiveWhite)) { // If a white header directive matched
ScanResultType = WhitePattern; // then we have a "WhitePattern'. ScanResultType = WhitePattern; // then we have a "WhitePattern'.
} else } else

+ 2
- 1
SNFMulti.hpp View File

#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <ctime> #include <ctime>
#include <string>
#include <string>
#include "../CodeDweller/faults.hpp"
#include "../CodeDweller/threading.hpp" #include "../CodeDweller/threading.hpp"
#include "GBUdb.hpp" #include "GBUdb.hpp"
#include "FilterChain.hpp" #include "FilterChain.hpp"

+ 1
- 1
snfXCImgr.cpp View File

break; // break out of the loop. break; // break out of the loop.


} else { // When we have a job to do: } else { // When we have a job to do:
int XCIMode;
int XCIMode = XCI_Reading;
try { try {
CurrentThreadState(XCI_Read); CurrentThreadState(XCI_Read);
XCIMode = XCI_Reading; // Now we are reading. XCIMode = XCI_Reading; // Now we are reading.

+ 3
- 1
snf_engine.cpp View File

} }


// TokenMatrix::Load(stream) // TokenMatrix::Load(stream)
const AbortCheck CompatibleIntSizeCheck("TokenMatrix::Load():CompatibleIntSizeCheck(sizeof(unsigned int)==4)");


void TokenMatrix::Load(ifstream& F) { // Initializes the token matrix from a file. void TokenMatrix::Load(ifstream& F) { // Initializes the token matrix from a file.
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions.


MatrixSize = 0; // Clear out the old Matrix Size and array. MatrixSize = 0; // Clear out the old Matrix Size and array.
if(Matrix) delete Matrix; // that is, if there is an array. if(Matrix) delete Matrix; // that is, if there is an array.
} }


void TokenMatrix::FlipEndian() { // Converts big/little endian tokens. void TokenMatrix::FlipEndian() { // Converts big/little endian tokens.
assert(sizeof(unsigned int)==4); // Check our assumptions.
unsigned int* UInts = reinterpret_cast<unsigned int*>(Matrix); // Grab the matrix as uints. unsigned int* UInts = reinterpret_cast<unsigned int*>(Matrix); // Grab the matrix as uints.
int Length = ((MatrixSize * sizeof(Token)) / sizeof(unsigned int)); // Calculate it's size. int Length = ((MatrixSize * sizeof(Token)) / sizeof(unsigned int)); // Calculate it's size.
for(int i = 0; i < Length; i++) { // Loop through the array of u ints for(int i = 0; i < Length; i++) { // Loop through the array of u ints

+ 2
- 1
snf_engine.hpp View File

#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <exception>
#include <exception>
#include "../CodeDweller/faults.hpp"
#include "../CodeDweller/mangler.hpp" #include "../CodeDweller/mangler.hpp"
//#include "../nvwa-0.6/nvwa/debug_new.h" //#include "../nvwa-0.6/nvwa/debug_new.h"



Loading…
Cancel
Save