Fix unable to parse nmap output for incomplete XML output #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #122
According to golang standard library documentation in https://pkg.go.dev/os/exec#Cmd.StdoutPipe
And in
nmap/nmap.go
Line 149 in a750324
Wait
is called whileio.Copy
([1] , [2]) is still performing reads onstdoutDuplicate
.The fix is inspired from a solution to a similar simplified problem
Before calling
Wait
we wait on a WaitGroup than is done when all reads onstdoutDuplicate
have completed.Finally I've added a test that runs a thousand nmap scans (takes about 5 seconds). The scans are done without a host so it returns almost immediately. You can verify the test fails when commenting out
wg.Wait()
in nmap.go on line 161. You can verify the test doesn't fail with thatwg.Wait()
.Feel free to remove the test from the MR if you think it's not worth to keep it once the fix is confirmed to be working.