@@ -96,13 +96,13 @@ def run
96
96
97
97
loop do
98
98
# Stop scanning if we hit a fatal error
99
- break if @scan_errors . length > 0
99
+ break if has_fatal_errors?
100
100
101
101
# Spawn threads for each host
102
102
while ( @tl . length < threads_max )
103
103
104
104
# Stop scanning if we hit a fatal error
105
- break if @scan_errors . length > 0
105
+ break if has_fatal_errors?
106
106
107
107
ip = ar . next_ip
108
108
break if not ip
@@ -131,7 +131,7 @@ def run
131
131
end
132
132
133
133
# Stop scanning if we hit a fatal error
134
- break if @scan_errors . length > 0
134
+ break if has_fatal_errors?
135
135
136
136
# Exit once we run out of hosts
137
137
if ( @tl . length == 0 )
@@ -152,7 +152,7 @@ def run
152
152
scanner_show_progress ( ) if @show_progress
153
153
end
154
154
155
- scanner_report_fatal_errors
155
+ scanner_handle_fatal_errors
156
156
return
157
157
end
158
158
@@ -171,7 +171,7 @@ def run
171
171
nohosts = false
172
172
173
173
# Stop scanning if we hit a fatal error
174
- break if @scan_errors . length > 0
174
+ break if has_fatal_errors?
175
175
176
176
while ( @tl . length < threads_max )
177
177
@@ -218,7 +218,7 @@ def run
218
218
end
219
219
220
220
# Stop scanning if we hit a fatal error
221
- break if @scan_errors . length > 0
221
+ break if has_fatal_errors?
222
222
223
223
# Exit if there are no more pending threads
224
224
if ( @tl . length == 0 )
@@ -241,7 +241,7 @@ def run
241
241
scanner_show_progress ( ) if @show_progress
242
242
end
243
243
244
- scanner_report_fatal_errors
244
+ scanner_handle_fatal_errors
245
245
return
246
246
end
247
247
@@ -264,18 +264,23 @@ def seppuko!
264
264
end
265
265
end
266
266
267
- def scanner_report_fatal_errors
268
- return unless @scan_errors && @scan_errors . length > 0
267
+ def has_fatal_errors?
268
+ @scan_errors && !@scan_errors . empty?
269
+ end
270
+
271
+ def scanner_handle_fatal_errors
272
+ return unless has_fatal_errors?
269
273
return unless @tl
270
274
271
275
# First kill any running threads
272
276
@tl . each { |t | t . kill if t . alive? }
273
277
274
278
# Show the unique errors triggered by the scan
275
- @scan_errors . uniq . each do |emsg |
279
+ uniq_errors = @scan_errors . uniq
280
+ uniq_errors . each do |emsg |
276
281
print_error ( "Fatal: #{ emsg } " )
277
282
end
278
- print_status ( "Scan terminated due to one or more fatal errors " )
283
+ print_error ( "Scan terminated due to #{ uniq_errors . size } fatal error(s) " )
279
284
end
280
285
281
286
def scanner_progress
@@ -284,6 +289,8 @@ def scanner_progress
284
289
end
285
290
286
291
def scanner_show_progress
292
+ # it should already be in the process of shutting down if there are fatal errors
293
+ return if has_fatal_errors?
287
294
pct = scanner_progress
288
295
if pct >= ( @range_percent + @show_percent )
289
296
@range_percent = @range_percent + @show_percent
0 commit comments