mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
Merge pull request #706 from boolooper/master
Improve code and fix race conditions
This commit is contained in:
commit
1cf74121a3
8 changed files with 9 additions and 12 deletions
|
@ -75,7 +75,7 @@ func (mod *EventsStream) dumpForm(body []byte) string {
|
|||
if err != nil {
|
||||
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"
|
||||
|
@ -113,7 +113,7 @@ func (mod *EventsStream) dumpJSON(body []byte) string {
|
|||
if err := json.Indent(&buf, body, "", " "); err != nil {
|
||||
pretty = string(body)
|
||||
} else {
|
||||
pretty = string(buf.Bytes())
|
||||
pretty = buf.String()
|
||||
}
|
||||
|
||||
return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n"
|
||||
|
|
|
@ -121,7 +121,7 @@ func (mod *MySQLServer) Start() error {
|
|||
if _, err := conn.Write(packets.MySQLGreeting); err != nil {
|
||||
mod.Warning("error while writing server greeting: %s", err)
|
||||
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)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
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 := ""
|
||||
for name, value := range data {
|
||||
s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value))
|
||||
|
|
|
@ -227,8 +227,8 @@ func (mod *SynScanner) synScan() error {
|
|||
mod.State.Store("progress", 0.0)
|
||||
|
||||
// start the collector
|
||||
mod.waitGroup.Add(1)
|
||||
go func() {
|
||||
mod.waitGroup.Add(1)
|
||||
defer mod.waitGroup.Done()
|
||||
|
||||
for packet := range mod.packets {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
mod.writes.Add(1)
|
||||
go func() {
|
||||
mod.writes.Add(1)
|
||||
defer mod.writes.Done()
|
||||
|
||||
// since we need to change the wifi adapter channel for each
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
||||
mod.writes.Add(1)
|
||||
go func() {
|
||||
mod.writes.Add(1)
|
||||
defer mod.writes.Done()
|
||||
|
||||
// since we need to change the wifi adapter channel for each
|
||||
|
|
|
@ -92,7 +92,7 @@ func (mod *WiFiModule) channelHopper() {
|
|||
}
|
||||
|
||||
select {
|
||||
case _ = <-mod.hopChanges:
|
||||
case <-mod.hopChanges:
|
||||
mod.Debug("hop changed")
|
||||
break loopCurrentChannels
|
||||
case <-time.After(delay):
|
||||
|
|
|
@ -65,9 +65,7 @@ func (p *EventPool) Listen() <-chan Event {
|
|||
go func() {
|
||||
for i := len(p.events) - 1; i >= 0; i-- {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
|
||||
}
|
||||
recover()
|
||||
}()
|
||||
l <- p.events[i]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue