-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ext/vulnsrc/oracle: fix ELSA version comparison #366
Conversation
ext/vulnsrc/oracle/oracle.go
Outdated
@@ -115,7 +150,7 @@ func (u *updater) Update(datastore database.Datastore) (resp vulnsrc.UpdateRespo | |||
r := elsaRegexp.FindStringSubmatch(line) | |||
if len(r) == 2 { | |||
elsaNo, _ := strconv.Atoi(r[1]) | |||
if elsaNo > firstELSA { | |||
if compareELSA(elsaNo, firstELSA) == 1 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually you'd test for > 0
because this kind of comparison functions typically only offers the sign and 0 guarantees (C / Java) and return a distance/difference between the two (at least for the first part that is different).
i.e. return len(lstr) - len(rstr)
ext/vulnsrc/oracle/oracle.go
Outdated
} else if len(lstr) > len(rstr) { | ||
return 1 | ||
} | ||
return -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole block can be replaced by return len(lstr) - len(rstr)
- typically what's used.
return 1 | ||
} else if ldigit < rdigit { | ||
return -1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can test for eq and return the diff too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, the equal case here should be continue
which it already falls back to.
Go linters always want you to drop the last case like this /shrug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i meant, you can do:
if ldigit != rdigit {
return ldigit - rdigit
}
Previously we naively compared integers. However, not all versions have the same length.
ext/vulnsrc/oracle: fix ELSA version comparison
Previously we naively compared integers. However, not all versions have
the same length.