Check for number of addr entries
This commit is contained in:
parent
75d1c1f2f4
commit
ec616a0151
|
@ -112,6 +112,7 @@ exports.addr = {
|
||||||
decode: function(buf) {
|
decode: function(buf) {
|
||||||
var decoded = structs.var_int.decode(buf);
|
var decoded = structs.var_int.decode(buf);
|
||||||
var listLength = decoded.value;
|
var listLength = decoded.value;
|
||||||
|
assert(listLength <= 1000, "Too many address entires");
|
||||||
var length = decoded.length + listLength * 38;
|
var length = decoded.length + listLength * 38;
|
||||||
assert(buf.length >= length, "Buffer is too small");
|
assert(buf.length >= length, "Buffer is too small");
|
||||||
var rest = decoded.rest;
|
var rest = decoded.rest;
|
||||||
|
@ -132,6 +133,7 @@ exports.addr = {
|
||||||
* @return {Buffer} Encoded `addr` payload.
|
* @return {Buffer} Encoded `addr` payload.
|
||||||
*/
|
*/
|
||||||
encode: function(addrs) {
|
encode: function(addrs) {
|
||||||
|
assert(addrs.length <= 1000, "Too many address entires");
|
||||||
var addrsBuf = Buffer.concat(addrs.map(structs.net_addr.encode));
|
var addrsBuf = Buffer.concat(addrs.map(structs.net_addr.encode));
|
||||||
return Buffer.concat([structs.var_int.encode(addrs.length), addrsBuf]);
|
return Buffer.concat([structs.var_int.encode(addrs.length), addrsBuf]);
|
||||||
},
|
},
|
||||||
|
|
5
test.js
5
test.js
|
@ -320,6 +320,11 @@ describe("Message types", function() {
|
||||||
expect(res.addrs[1].host).to.equal("ff:0:0:0:0:0:0:1");
|
expect(res.addrs[1].host).to.equal("ff:0:0:0:0:0:0:1");
|
||||||
expect(res.addrs[1].port).to.equal(18444);
|
expect(res.addrs[1].port).to.equal(18444);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shouldn't encode/decode more than 1000 entires", function() {
|
||||||
|
expect(addr.encode.bind(null, Array(2000))).to.throw(/too many/i);
|
||||||
|
expect(addr.decode.bind(null, var_int.encode(2000))).to.throw(/too many/i);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user