Explorar el Código

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 hace 15 años
padre
commit
a457509f6a
Se han modificado 7 ficheros con 32 adiciones y 14 borrados
  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 Ver fichero

@@ -333,6 +333,8 @@ void GBUdbDataset::save() {
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.

@@ -343,7 +345,7 @@ void GBUdbDataset::load() {
dbFile.seekg(0, ios::beg); // determine it's size.

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?

@@ -556,7 +558,7 @@ GBUdbAlert::GBUdbAlert() :
string GBUdbAlert::toXML() { // Convert this alert to XML text
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.
case Good: { FlagName = "Good"; break; } // Convert each value to it's name.
case Bad: { FlagName = "Bad"; break; }

+ 1
- 0
GBUdb.hpp Ver fichero

@@ -11,6 +11,7 @@
#ifndef M_GBUdb
#define M_GBUdb

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

+ 19
- 8
SNFMulti.cpp Ver fichero

@@ -23,7 +23,7 @@ using namespace std;

//// 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

@@ -331,9 +331,11 @@ bool snf_RulebaseHandler::AutoRefresh() {
// 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
// load activity.
const LogicCheck SaneRefreshProcessCheck("snf_RulebaseHandler::_snf_LoadNewRulebase():SaneRefreshProcessCheck(RefreshInProgress)");

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.
catch(...) { // If something goes wrong:
RefreshInProgress = false; // we are no longer "in refresh"
@@ -1265,6 +1267,9 @@ string snf_EngineHandler::extractMessageID(

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).
const unsigned char* inputMessageBuffer, // -- this is the message buffer.
@@ -1274,9 +1279,16 @@ int snf_EngineHandler::scanMessage(
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...

// Preliminary job setup.
@@ -1285,9 +1297,8 @@ int snf_EngineHandler::scanMessage(
// originals and then use the captured values. For example if we are scanning
// 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.ScanSize = MessageLength; // Grab the message length.
@@ -1609,7 +1620,7 @@ int snf_EngineHandler::scanMessage(

// 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
ScanResultType = WhitePattern; // then we have a "WhitePattern'.
} else

+ 2
- 1
SNFMulti.hpp Ver fichero

@@ -28,7 +28,8 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <ctime>
#include <string>
#include <string>
#include "../CodeDweller/faults.hpp"
#include "../CodeDweller/threading.hpp"
#include "GBUdb.hpp"
#include "FilterChain.hpp"

+ 1
- 1
snfXCImgr.cpp Ver fichero

@@ -455,7 +455,7 @@ void snfXCITCPChannel::myTask() {
break; // break out of the loop.

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

+ 3
- 1
snf_engine.cpp Ver fichero

@@ -64,8 +64,11 @@ void TokenMatrix::Load(const char* FileName) {
}

// 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.
CompatibleIntSizeCheck(sizeof(unsigned int)==4); // Check our assumptions.

MatrixSize = 0; // Clear out the old Matrix Size and array.
if(Matrix) delete Matrix; // that is, if there is an array.
@@ -199,7 +202,6 @@ void TokenMatrix::Verify(string& SecurityKey) {
}

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.
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

+ 2
- 1
snf_engine.hpp Ver fichero

@@ -39,7 +39,8 @@
#include <fstream>
#include <iostream>
#include <string>
#include <exception>
#include <exception>
#include "../CodeDweller/faults.hpp"
#include "../CodeDweller/mangler.hpp"
//#include "../nvwa-0.6/nvwa/debug_new.h"


Cargando…
Cancelar
Guardar