Fix buffer length calculation in ServerAdvertisement (#292)

This commit is contained in:
Kurt Thiemann 2022-10-04 08:57:00 +02:00 committed by GitHub
commit 9724ff41ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,8 +51,9 @@ class ServerAdvertisement {
toBuffer (version) {
const str = this.toString(version)
const buf = Buffer.alloc(2 + str.length)
buf.writeUInt16BE(str.length, 0)
const length = Buffer.byteLength(str)
const buf = Buffer.alloc(2 + length)
buf.writeUInt16BE(length, 0)
buf.write(str, 2)
return buf
}