Merge pull request #706 from boolooper/master

Improve code and fix race conditions
This commit is contained in:
Simone Margaritelli 2020-04-08 10:46:55 +02:00 committed by GitHub
commit 1cf74121a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 9 additions and 12 deletions

View file

@ -75,7 +75,7 @@ func (mod *EventsStream) dumpForm(body []byte) string {
if err != nil { if err != nil {
value = v value = v
} }
form = append(form, fmt.Sprintf("%s", tui.Bold(tui.Red(value)))) form = append(form, tui.Bold(tui.Red(value)))
} }
} }
return "\n" + strings.Join(form, "&") + "\n" return "\n" + strings.Join(form, "&") + "\n"
@ -113,7 +113,7 @@ func (mod *EventsStream) dumpJSON(body []byte) string {
if err := json.Indent(&buf, body, "", " "); err != nil { if err := json.Indent(&buf, body, "", " "); err != nil {
pretty = string(body) pretty = string(body)
} else { } else {
pretty = string(buf.Bytes()) pretty = buf.String()
} }
return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n" return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n"

View file

@ -121,7 +121,7 @@ func (mod *MySQLServer) Start() error {
if _, err := conn.Write(packets.MySQLGreeting); err != nil { if _, err := conn.Write(packets.MySQLGreeting); err != nil {
mod.Warning("error while writing server greeting: %s", err) mod.Warning("error while writing server greeting: %s", err)
continue continue
} else if read, err = reader.Read(readBuffer); err != nil { } else if _, err = reader.Read(readBuffer); err != nil {
mod.Warning("error while reading client message: %s", err) mod.Warning("error while reading client message: %s", err)
continue continue
} }

View file

@ -13,7 +13,7 @@ import (
) )
func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool { func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool {
if data := packets.UPNPGetMeta(pkt); data != nil && len(data) > 0 { if data := packets.UPNPGetMeta(pkt); len(data) > 0 {
s := "" s := ""
for name, value := range data { for name, value := range data {
s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value)) s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value))

View file

@ -227,8 +227,8 @@ func (mod *SynScanner) synScan() error {
mod.State.Store("progress", 0.0) mod.State.Store("progress", 0.0)
// start the collector // start the collector
mod.waitGroup.Add(1)
go func() { go func() {
mod.waitGroup.Add(1)
defer mod.waitGroup.Done() defer mod.waitGroup.Done()
for packet := range mod.packets { for packet := range mod.packets {

View file

@ -88,9 +88,8 @@ func (mod *WiFiModule) startAssoc(to net.HardwareAddr) error {
} }
return fmt.Errorf("%s is an unknown BSSID or it is in the association skip list.", to.String()) return fmt.Errorf("%s is an unknown BSSID or it is in the association skip list.", to.String())
} }
mod.writes.Add(1)
go func() { go func() {
mod.writes.Add(1)
defer mod.writes.Done() defer mod.writes.Done()
// since we need to change the wifi adapter channel for each // since we need to change the wifi adapter channel for each

View file

@ -113,8 +113,8 @@ func (mod *WiFiModule) startDeauth(to net.HardwareAddr) error {
return fmt.Errorf("%s is an unknown BSSID, is in the deauth skip list, or doesn't have detected clients.", to.String()) return fmt.Errorf("%s is an unknown BSSID, is in the deauth skip list, or doesn't have detected clients.", to.String())
} }
mod.writes.Add(1)
go func() { go func() {
mod.writes.Add(1)
defer mod.writes.Done() defer mod.writes.Done()
// since we need to change the wifi adapter channel for each // since we need to change the wifi adapter channel for each

View file

@ -92,7 +92,7 @@ func (mod *WiFiModule) channelHopper() {
} }
select { select {
case _ = <-mod.hopChanges: case <-mod.hopChanges:
mod.Debug("hop changed") mod.Debug("hop changed")
break loopCurrentChannels break loopCurrentChannels
case <-time.After(delay): case <-time.After(delay):

View file

@ -65,9 +65,7 @@ func (p *EventPool) Listen() <-chan Event {
go func() { go func() {
for i := len(p.events) - 1; i >= 0; i-- { for i := len(p.events) - 1; i >= 0; i-- {
defer func() { defer func() {
if recover() != nil { recover()
}
}() }()
l <- p.events[i] l <- p.events[i]
} }