Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suback fails validation of packets with QoS 128 #134

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ class Parser extends EventEmitter {
return this._emitError(new Error('Invalid suback code'))
}
} else {
if (code > 2) {
return this._emitError(new Error('Invalid suback QoS, must be <= 2'))
if (code > 2 && code !== 0x80) {
return this._emitError(new Error('Invalid suback QoS, must be 0, 1, 2 or 128'))
}
}
this.packet.granted.push(code)
Expand Down Expand Up @@ -800,7 +800,7 @@ class Parser extends EventEmitter {
}

_emitError (err) {
debug('_emitError')
debug('_emitError', err)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed because when looking for this error I had no clue what was going on even by enabling debug, I just saw an emitError log that doens't say anything about why it's failing

this.error = err
this.emit('error', err)
}
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2266,10 +2266,10 @@ testParseGenerate('suback', {
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
]), { protocolVersion: 5 })

testParseError('Invalid suback QoS, must be <= 2', Buffer.from([
testParseError('Invalid suback QoS, must be 0, 1, 2 or 128', Buffer.from([
144, 6, // Header
0, 6, // Message ID
0, 1, 2, 128 // Granted qos (0, 1, 2) and a rejected being 0x80
0, 1, 2, 3 // Granted qos (0, 1, 2)
]))

testParseError('Invalid suback code', Buffer.from([
Expand Down