Skip to content

Commit

Permalink
v1.28.1
Browse files Browse the repository at this point in the history
fixed crash on malformed list of downstream/upstream ASes (#593)
  • Loading branch information
massimocandela authored Jun 24, 2021
1 parent b621fbe commit 9419444
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bgpalerter",
"version": "1.28.0",
"version": "1.28.1",
"description": "Software to monitor streams of BGP data. Pre-configured for real-time detection of visibility loss, RPKI invalid announcements, hijacks, and more.",
"author": {
"name": "Massimo Candela",
Expand Down
29 changes: 20 additions & 9 deletions src/inputs/inputYml.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ export default class InputYml extends Input {
group: 'default'
}, monitoredPrefixesFile.options.monitorASns[asn]);

if (item.upstreams) item.upstreams = new AS(item.upstreams);
if (item.downstreams) item.downstreams = new AS(item.downstreams);
if (item.upstreams && item.upstreams.length) {
item.upstreams = new AS(item.upstreams);
}
if (item.downstreams && item.downstreams.length) {
item.downstreams = new AS(item.downstreams);
}

return item;
});
Expand Down Expand Up @@ -184,13 +188,20 @@ export default class InputYml extends Input {
const options = fileContent.options;

if (options && options.monitorASns) {
optionsError = Object
.keys(options.monitorASns)
.map(asn => {
if (!new AS(asn).isValid()) {
return "Not a valid AS number in monitorASns";
}
});

for (let item in options.monitorASns) {
if (!new AS(item).isValid()) {
optionsError.push("Not a valid AS number in monitorASns");
}
const upstreams = options.monitorASns[item].upstreams;
const downstreams = options.monitorASns[item].downstreams;
if (upstreams && upstreams.length && !new AS(upstreams).isValid()) {
optionsError.push(`One of the upstream ASes provided for AS${item} is not valid`);
}
if (downstreams && downstreams.length && !new AS(downstreams).isValid()) {
optionsError.push(`One of the downstream ASes provided for AS${item} is not valid`);
}
}
}

prefixesError = Object
Expand Down
23 changes: 11 additions & 12 deletions src/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,22 @@ export class AS {
if (["string", "number"].includes(typeof(numbers))) {
this.numbers = [ numbers ];
} else if (numbers instanceof Array && numbers.length){
this.ASset = true;
if (numbers.length === 1) {
this.numbers = [ numbers[0] ];
} else {
this.numbers = numbers;
if (numbers.length > 1) {
this.ASset = true;
}
this.numbers = numbers;
}

if (this.isValid()) {
this.numbers = this.numbers.map(i => parseInt(i));
}

const key = this.numbers.join("-");
if (!!AS._instances[key]) {
return AS._instances[key];
}
const key = this.numbers.join("-");
if (!!AS._instances[key]) {
return AS._instances[key];
}

AS._instances[key] = this;
AS._instances[key] = this;
}
}

getId () {
Expand All @@ -82,7 +80,8 @@ export class AS {

isValid () {
if (this._valid === null) {
this._valid = this.numbers.length > 0 &&
this._valid = this.numbers &&
this.numbers.length > 0 &&
this.numbers
.every(asn => {

Expand Down

0 comments on commit 9419444

Please sign in to comment.