Merge pull request #319 from alxhotel/validate-port

Add validation for tracker port
This commit is contained in:
Diego Rodríguez Baquero 2019-04-08 09:17:18 -05:00 committed by GitHub
commit b0efe653fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -85,7 +85,14 @@ class Client extends EventEmitter {
this._trackers = announce
.map(announceUrl => {
const protocol = url.parse(announceUrl).protocol
const parsedUrl = url.parse(announceUrl)
const port = parsedUrl.port
if (port < 0 || port > 65535) {
nextTickWarn(new Error(`Invalid tracker port: ${announceUrl}`))
return null
}
const protocol = parsedUrl.protocol
if ((protocol === 'http:' || protocol === 'https:') &&
typeof HTTPTracker === 'function') {
return new HTTPTracker(this, announceUrl)