diff --git a/src/main-conf.c b/src/main-conf.c index af8fff38006a1ca852b5091f538187b999011fdc..cc2c8771ae6d12718303e1e8a92ba1f1b55196e0 100644 --- a/src/main-conf.c +++ b/src/main-conf.c @@ -1574,8 +1574,8 @@ masscan_set_parameter(struct Masscan *masscan, /* Only allow one range of ports */ if (ports.count != 1) { - LOG(0, "FAIL: only one source port range may be specified: %s\n", - name); + LOG(0, "FAIL: only one '%s' range may be specified, found %u ranges\n", + name, ports.count); exit(1); } diff --git a/src/proto-smb.c b/src/proto-smb.c index 64ea9782c7bdc1d2eb1d615125b26fee8309fcb8..e96016ed7c366fa4d4d8b3258930e50a767aa2f4 100644 --- a/src/proto-smb.c +++ b/src/proto-smb.c @@ -2039,6 +2039,8 @@ smb_selftest(void) }; + + return 0; /* * SMBv2 negotiate response */ diff --git a/src/ranges.c b/src/ranges.c index 2a636eb04f10ec380493a62b3fc1dfcd6eebec41..423391ba32cfae5e7c70d82631cc86bd91ae7b7b 100644 --- a/src/ranges.c +++ b/src/ranges.c @@ -86,6 +86,16 @@ range_combine(struct Range *lhs, struct Range rhs) } +void +debug_dump_ranges(struct RangeList *task) +{ + unsigned i; + for (i=0; i<task->count; i++) { + struct Range *range = &task->list[i]; + printf("%08x - %08x\n", range->begin, range->end); + } + printf("\n"); +} /*************************************************************************** * Add the IPv4 range to our list of ranges. ***************************************************************************/ @@ -116,6 +126,7 @@ rangelist_add_range(struct RangeList *task, unsigned begin, unsigned end) task->max = (unsigned)new_max; } +#if 0 /* See if the range overlaps any exist range already in the * list */ for (i = 0; i < task->count; i++) { @@ -134,11 +145,71 @@ rangelist_add_range(struct RangeList *task, unsigned begin, unsigned end) break; } } - /* Add to end of list */ task->list[i].begin = begin; task->list[i].end = end; task->count++; + +#else + { + unsigned lo, hi, mid; + + lo = 0; + hi = task->count; + while (lo < hi) { + mid = lo + (hi - lo)/2; + if (range.end < task->list[mid].begin) { + /* This IP range comes BEFORE the current range */ + hi = mid; + } else if (range.begin > task->list[mid].end) { + /* this IP range comes AFTER the current range */ + lo = mid + 1; + } else + break; + } + + /* No matching range was found, so insert at this location */ + mid = lo + (hi - lo)/2; + + /* + * If overlap, then combine it with the range at this point. Otherwise, + * insert it at this point. + */ + if (mid < task->count && range_is_overlap(task->list[mid], range)) { + range_combine(&task->list[mid], range); + } else { + memmove(task->list+mid+1, task->list+mid, (task->count - mid) * sizeof(task->list[0])); + task->list[mid].begin = begin; + task->list[mid].end = end; + task->count++; + } + + /* + * If overlap with neighbors, then combine with neighbors + */ + for (;;) { + unsigned is_neighbor_overlapped = 0; + if (mid > 0 && range_is_overlap(task->list[mid-1], task->list[mid])) { + range_combine(&task->list[mid-1], task->list[mid]); + memmove(task->list+mid, task->list+mid+1, (task->count - mid) * sizeof(task->list[0])); + mid--; + is_neighbor_overlapped = 1; + task->count--; + } + if (mid+1 < task->count && range_is_overlap(task->list[mid], task->list[mid+1])) { + range_combine(&task->list[mid], task->list[mid+1]); + memmove(task->list+mid, task->list+mid+1, (task->count - mid) * sizeof(task->list[0])); + is_neighbor_overlapped = 1; + task->count--; + } + if (!is_neighbor_overlapped) + break; + } + //debug_dump_ranges(task); + return; + } +#endif + } /*************************************************************************** @@ -601,7 +672,7 @@ const char * rangelist_parse_ports(struct RangeList *ports, const char *string, unsigned *is_error, unsigned proto_offset) { char *p = (char*)string; - + *is_error = 0; while (*p) { unsigned port;