Skip to content

Commit

Permalink
fix issue with channel handling
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Nov 2, 2024
1 parent 0a013a6 commit 7425adf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions modules/mqtt/mqtt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ func (t *mqttTester) getScanner() (*Scanner, error) {
flags.SubscribeTopics = "#,$SYS/#"
flags.SubscribeTimeout = 10 * time.Second
flags.TopicsSeparator = ","
flags.LimitMessages = 1
flags.LimitTopics = 10

// Attempt anonymous auth with
// an empty user and password as the
Expand Down
11 changes: 7 additions & 4 deletions modules/mqtt/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,17 @@ func (scan *scan) Grab() *zgrab2.ScanError {
}

go func() {
time.Sleep(scan.scanner.config.SubscribeTimeout)
<-time.After(scan.scanner.config.SubscribeTimeout)
scan.client.Unsubscribe(subs...)
close(msgs)
}()

topics := make(map[string][]string)
for m := range msgs {
// handle here to addd the results to the scan
msgs := topics[m.Topic()]
msgs = append(msgs, string(m.Payload()))
topics[m.Topic()] = msgs
msg := topics[m.Topic()]
msg = append(msg, string(m.Payload()))
topics[m.Topic()] = msg
}
scan.results.Topics = topics
return nil
Expand All @@ -226,6 +226,9 @@ func (scanner *Scanner) Protocol() string {
// Init initializes the Scanner.
func (scanner *Scanner) Init(flags zgrab2.ScanFlags) error {
scanner.config = flags.(*Flags)
if scanner.config.SubscribeTimeout <= 0 {
scanner.config.SubscribeTimeout = 10 * time.Second
}
return nil
}

Expand Down

0 comments on commit 7425adf

Please sign in to comment.