mirror of
https://github.com/nmap/nmap.git
synced 2025-12-07 13:11:28 +00:00
Avoid runaway recursion in service scan, similar to #3130
This commit is contained in:
@@ -219,6 +219,7 @@ public:
|
|||||||
unsigned int ideal_parallelism; // Max (and desired) number of probes out at once.
|
unsigned int ideal_parallelism; // Max (and desired) number of probes out at once.
|
||||||
ScanProgressMeter *SPM;
|
ScanProgressMeter *SPM;
|
||||||
int num_hosts_timedout; // # of hosts timed out during (or before) scan
|
int num_hosts_timedout; // # of hosts timed out during (or before) scan
|
||||||
|
bool busy; // Recursion guard; if true, don't start any new events
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SUBSTARGS_MAX_ARGS 5
|
#define SUBSTARGS_MAX_ARGS 5
|
||||||
@@ -2057,6 +2058,7 @@ static void adjustPortStateIfNecessary(ServiceNFO *svc) {
|
|||||||
ServiceProbe *probe) {
|
ServiceProbe *probe) {
|
||||||
const u8 *probestring;
|
const u8 *probestring;
|
||||||
int probestringlen;
|
int probestringlen;
|
||||||
|
ServiceGroup *SG = (ServiceGroup *) nsock_pool_get_udata(nsp);
|
||||||
|
|
||||||
// Report data as probes are sent if --version-trace has been requested
|
// Report data as probes are sent if --version-trace has been requested
|
||||||
if (o.debugging > 1 || o.versionTrace()) {
|
if (o.debugging > 1 || o.versionTrace()) {
|
||||||
@@ -2069,8 +2071,10 @@ static void adjustPortStateIfNecessary(ServiceNFO *svc) {
|
|||||||
probestring = probe->getProbeString(&probestringlen);
|
probestring = probe->getProbeString(&probestringlen);
|
||||||
assert(probestringlen > 0);
|
assert(probestringlen > 0);
|
||||||
// Now we write the string to the IOD
|
// Now we write the string to the IOD
|
||||||
|
SG->busy = 1;
|
||||||
nsock_write(nsp, nsi, servicescan_write_handler, svc->probe_timemsleft(probe), svc,
|
nsock_write(nsp, nsi, servicescan_write_handler, svc->probe_timemsleft(probe), svc,
|
||||||
(const char *) probestring, probestringlen);
|
(const char *) probestring, probestringlen);
|
||||||
|
SG->busy = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2094,8 +2098,10 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
|
|||||||
if (probe) {
|
if (probe) {
|
||||||
svc->currentprobe_exec_time = *nsock_gettimeofday();
|
svc->currentprobe_exec_time = *nsock_gettimeofday();
|
||||||
send_probe_text(nsp, nsi, svc, probe);
|
send_probe_text(nsp, nsi, svc, probe);
|
||||||
|
if (svc->probe_state < PROBESTATE_FINISHED_HARDMATCHED) {
|
||||||
nsock_read(nsp, nsi, servicescan_read_handler,
|
nsock_read(nsp, nsi, servicescan_read_handler,
|
||||||
svc->probe_timemsleft(probe, nsock_gettimeofday()), svc);
|
svc->probe_timemsleft(probe, nsock_gettimeofday()), svc);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Should only happen if someone has a highly perverse nmap-service-probes
|
// Should only happen if someone has a highly perverse nmap-service-probes
|
||||||
// file. Null scan should generally never be the only probe.
|
// file. Null scan should generally never be the only probe.
|
||||||
@@ -2292,6 +2298,11 @@ static void end_svcprobe(enum serviceprobestate probe_state, ServiceGroup *SG, S
|
|||||||
static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
|
static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
|
||||||
ServiceNFO *svc;
|
ServiceNFO *svc;
|
||||||
static int warn_no_scanning=1;
|
static int warn_no_scanning=1;
|
||||||
|
if (SG->busy) {
|
||||||
|
// "busy" means a Nsock callback is being called synchronously;
|
||||||
|
// Don't launch any probes or we risk runaway recursion.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
while (SG->services_in_progress.size() < SG->ideal_parallelism &&
|
while (SG->services_in_progress.size() < SG->ideal_parallelism &&
|
||||||
!SG->services_remaining.empty()) {
|
!SG->services_remaining.empty()) {
|
||||||
@@ -2369,7 +2380,9 @@ static void servicescan_connect_handler(nsock_pool nsp, nsock_event nse, void *m
|
|||||||
svc->currentprobe_exec_time = *nsock_gettimeofday();
|
svc->currentprobe_exec_time = *nsock_gettimeofday();
|
||||||
send_probe_text(nsp, nsi, svc, probe);
|
send_probe_text(nsp, nsi, svc, probe);
|
||||||
// Now let us read any results
|
// Now let us read any results
|
||||||
|
if (svc->probe_state < PROBESTATE_FINISHED_HARDMATCHED) {
|
||||||
nsock_read(nsp, nsi, servicescan_read_handler, svc->probe_timemsleft(probe, nsock_gettimeofday()), svc);
|
nsock_read(nsp, nsi, servicescan_read_handler, svc->probe_timemsleft(probe, nsock_gettimeofday()), svc);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case NSE_STATUS_TIMEOUT:
|
case NSE_STATUS_TIMEOUT:
|
||||||
|
|||||||
Reference in New Issue
Block a user