Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dadf9ee

Browse files
joshperrymcollina
andauthored
Confirm should not have a zero property length (#69)
cref rfc 3.4.2.2.1 Co-authored-by: Matteo Collina <[email protected]>
1 parent 6e8456b commit dadf9ee

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

parser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ Parser.prototype._parseConfirmation = function () {
421421
// response code
422422
packet.reasonCode = this._parseByte()
423423
debug('_parseConfirmation: packet.reasonCode `%d`', packet.reasonCode)
424+
}
425+
426+
if (packet.length > 3) {
424427
// properies mqtt 5
425428
var properties = this._parseProperties()
426429
if (Object.getOwnPropertyNames(properties).length) {

test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,20 @@ testParseGenerate('puback', {
10881088
0, 2 // Message ID
10891089
]))
10901090

1091+
testParseGenerate('puback with reason and no MQTT5 properties', {
1092+
cmd: 'puback',
1093+
retain: false,
1094+
qos: 0,
1095+
dup: false,
1096+
length: 3,
1097+
messageId: 2,
1098+
reasonCode: 16
1099+
}, Buffer.from([
1100+
64, 3, // Header
1101+
0, 2, // Message ID
1102+
16 // reason code
1103+
]), {protocolVersion: 5})
1104+
10911105
testParseGenerate('puback MQTT5 properties', {
10921106
cmd: 'puback',
10931107
retain: false,

writeToStream.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,12 @@ function confirmation (packet, stream, opts) {
384384
// properies mqtt 5
385385
var propertiesData = null
386386
if (version === 5) {
387-
propertiesData = getPropertiesByMaximumPacketSize(stream, properties, opts, length)
388-
if (!propertiesData) { return false }
389-
length += propertiesData.length
387+
// Confirm should not add empty property length with no properties (rfc 3.4.2.2.1)
388+
if (typeof properties === 'object') {
389+
propertiesData = getPropertiesByMaximumPacketSize(stream, properties, opts, length)
390+
if (!propertiesData) { return false }
391+
length += propertiesData.length
392+
}
390393
}
391394

392395
// Header

0 commit comments

Comments
 (0)