Roave / shorty

An asynchronous SMPP client and server built on Node.js. Shorty is sponsored and maintained by SMS Cloud, a subsidiary of Roave
http://roave.com/
GNU General Public License v3.0
92 stars 52 forks source link

PDU Parser fails when parsing type "string" #25

Open MichaelKling opened 6 years ago

MichaelKling commented 6 years ago

Parsing an incomming (deliver_sm) sms, the library crashed with the following error:

RangeError: out of range index
    at RangeError (native)
    at Object.exports.parse (.\node_modules\shorty\lib\pdu-parser.js:163:20)
    at Object.exports.fromBuffer (.\node_modules\shorty\lib\data-handler.js:76:22)
...

It seems that even though in the comment of the function it is explicitly stated

the length of the string will be specified by the value parsed in the field named by length_field

, the copy call in line 163 is still using field.length, instead of the determined length in line 161. But field.length is undefined in that case.

Changing line 163 from buffer.copy(temp, 0, offset, offset + field.length); to buffer.copy(temp, 0, offset, offset + length); seems to fix the issue.