mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 09:49:05 +00:00
Fix crash: manage lifetime of now-dynamic test results
This commit is contained in:
@@ -94,6 +94,7 @@ FingerPrintResultsIPv4::~FingerPrintResultsIPv4() {
|
|||||||
|
|
||||||
/* Free OS fingerprints of OS scanning was done */
|
/* Free OS fingerprints of OS scanning was done */
|
||||||
for(i=0; i < numFPs; i++) {
|
for(i=0; i < numFPs; i++) {
|
||||||
|
FPs[i]->erase();
|
||||||
delete(FPs[i]);
|
delete(FPs[i]);
|
||||||
FPs[i] = NULL;
|
FPs[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
26
osscan.cc
26
osscan.cc
@@ -84,13 +84,26 @@ FingerPrintDB::FingerPrintDB() : MatchPoints(NULL) {
|
|||||||
FingerPrintDB::~FingerPrintDB() {
|
FingerPrintDB::~FingerPrintDB() {
|
||||||
std::vector<FingerPrint *>::iterator current;
|
std::vector<FingerPrint *>::iterator current;
|
||||||
|
|
||||||
if (MatchPoints != NULL)
|
if (MatchPoints != NULL) {
|
||||||
|
MatchPoints->erase();
|
||||||
delete MatchPoints;
|
delete MatchPoints;
|
||||||
for (current = prints.begin(); current != prints.end(); current++)
|
}
|
||||||
|
for (current = prints.begin(); current != prints.end(); current++) {
|
||||||
|
(*current)->erase();
|
||||||
delete *current;
|
delete *current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FingerPrint::FingerPrint() {
|
FingerTest::FingerTest(bool allocResults) : name(NULL), results(NULL) {
|
||||||
|
if (allocResults)
|
||||||
|
this->results = new std::vector<struct AVal>;
|
||||||
|
}
|
||||||
|
|
||||||
|
void FingerTest::erase() {
|
||||||
|
if (this->results) {
|
||||||
|
delete this->results;
|
||||||
|
this->results = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FingerPrint::sort() {
|
void FingerPrint::sort() {
|
||||||
@@ -101,6 +114,13 @@ void FingerPrint::sort() {
|
|||||||
std::stable_sort(tests.begin(), tests.end());
|
std::stable_sort(tests.begin(), tests.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FingerPrint::erase() {
|
||||||
|
for (std::vector<FingerTest>::iterator t = this->tests.begin();
|
||||||
|
t != this->tests.end(); t++) {
|
||||||
|
t->erase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Compare an observed value (e.g. "45") against an OS DB expression (e.g.
|
/* Compare an observed value (e.g. "45") against an OS DB expression (e.g.
|
||||||
"3B-47" or "8|A" or ">10"). Return true iff there's a match. The syntax uses
|
"3B-47" or "8|A" or ">10"). Return true iff there's a match. The syntax uses
|
||||||
< (less than)
|
< (less than)
|
||||||
|
|||||||
15
osscan.h
15
osscan.h
@@ -93,6 +93,7 @@ enum dist_calc_method {
|
|||||||
struct AVal {
|
struct AVal {
|
||||||
const char *attribute;
|
const char *attribute;
|
||||||
const char *value;
|
const char *value;
|
||||||
|
AVal() : attribute(NULL), value(NULL) {}
|
||||||
|
|
||||||
bool operator<(const AVal& other) const {
|
bool operator<(const AVal& other) const {
|
||||||
return strcmp(attribute, other.attribute) < 0;
|
return strcmp(attribute, other.attribute) < 0;
|
||||||
@@ -126,28 +127,22 @@ struct FingerMatch {
|
|||||||
struct FingerTest {
|
struct FingerTest {
|
||||||
const char *name;
|
const char *name;
|
||||||
std::vector<struct AVal> *results;
|
std::vector<struct AVal> *results;
|
||||||
FingerTest() : name(NULL), results(NULL) {}
|
FingerTest(bool allocResults=false);
|
||||||
~FingerTest() {
|
~FingerTest() {
|
||||||
// name is allocated from string_pool
|
// name is allocated from string_pool
|
||||||
// results freed via ~FingerPrint()
|
// results must be freed manually
|
||||||
}
|
}
|
||||||
bool operator<(const FingerTest& other) const {
|
bool operator<(const FingerTest& other) const {
|
||||||
return strcmp(name, other.name) < 0;
|
return strcmp(name, other.name) < 0;
|
||||||
}
|
}
|
||||||
|
void erase();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FingerPrint {
|
struct FingerPrint {
|
||||||
FingerMatch match;
|
FingerMatch match;
|
||||||
std::vector<FingerTest> tests;
|
std::vector<FingerTest> tests;
|
||||||
FingerPrint();
|
|
||||||
~FingerPrint() {
|
|
||||||
for (std::vector<FingerTest>::iterator t = this->tests.begin();
|
|
||||||
t != this->tests.end(); t++) {
|
|
||||||
if (t->results)
|
|
||||||
delete t->results;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void sort();
|
void sort();
|
||||||
|
void erase();
|
||||||
};
|
};
|
||||||
/* This structure contains the important data from the fingerprint
|
/* This structure contains the important data from the fingerprint
|
||||||
database (nmap-os-db) */
|
database (nmap-os-db) */
|
||||||
|
|||||||
11
osscan2.cc
11
osscan2.cc
@@ -1029,8 +1029,10 @@ HostOsScanStats::~HostOsScanStats() {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < NUM_FPTESTS; i++) {
|
for (i = 0; i < NUM_FPTESTS; i++) {
|
||||||
if (FPtests[i] != NULL)
|
if (FPtests[i] != NULL) {
|
||||||
delete FPtests[i];
|
delete FPtests[i];
|
||||||
|
FPtests[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if (TOps_AVs[i])
|
if (TOps_AVs[i])
|
||||||
@@ -1148,9 +1150,10 @@ void HostOsScanStats::initScanStats() {
|
|||||||
|
|
||||||
FP = NULL;
|
FP = NULL;
|
||||||
for (i = 0; i < NUM_FPTESTS; i++) {
|
for (i = 0; i < NUM_FPTESTS; i++) {
|
||||||
if (FPtests[i] != NULL)
|
if (FPtests[i] != NULL) {
|
||||||
delete FPtests[i];
|
delete FPtests[i];
|
||||||
FPtests[i] = NULL;
|
FPtests[i] = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i < 6; i++) {
|
for (i = 0; i < 6; i++) {
|
||||||
if (TOps_AVs[i])
|
if (TOps_AVs[i])
|
||||||
@@ -2048,7 +2051,7 @@ void HostOsScan::makeFP(HostOsScanStats *hss) {
|
|||||||
/* We create a Resp (response) attribute with value of N (no) because
|
/* We create a Resp (response) attribute with value of N (no) because
|
||||||
it is important here to note whether responses were or were not
|
it is important here to note whether responses were or were not
|
||||||
received */
|
received */
|
||||||
hss->FPtests[i] = new FingerTest;
|
hss->FPtests[i] = new FingerTest(true);
|
||||||
AV.attribute = "R";
|
AV.attribute = "R";
|
||||||
AV.value = "N";
|
AV.value = "N";
|
||||||
hss->FPtests[i]->results->push_back(AV);
|
hss->FPtests[i]->results->push_back(AV);
|
||||||
|
|||||||
Reference in New Issue
Block a user