Merge pull request #3038 from wpaulino/tor-version-check
tor: use string comparison to check min supported version
This commit is contained in:
commit
44eb2320c7
@ -325,7 +325,6 @@ func computeHMAC256(key, message []byte) []byte {
|
|||||||
func supportsV3(version string) error {
|
func supportsV3(version string) error {
|
||||||
// We'll split the minimum Tor version that's supported and the given
|
// We'll split the minimum Tor version that's supported and the given
|
||||||
// version in order to individually compare each number.
|
// version in order to individually compare each number.
|
||||||
requiredParts := strings.Split(MinTorVersion, ".")
|
|
||||||
parts := strings.Split(version, ".")
|
parts := strings.Split(version, ".")
|
||||||
if len(parts) != 4 {
|
if len(parts) != 4 {
|
||||||
return errors.New("version string is not of the format " +
|
return errors.New("version string is not of the format " +
|
||||||
@ -338,22 +337,19 @@ func supportsV3(version string) error {
|
|||||||
build := strings.Split(parts[len(parts)-1], "-")
|
build := strings.Split(parts[len(parts)-1], "-")
|
||||||
parts[len(parts)-1] = build[0]
|
parts[len(parts)-1] = build[0]
|
||||||
|
|
||||||
// Convert them each number from its string representation to integers
|
// Ensure that each part of the version string corresponds to a number.
|
||||||
// and check that they respect the minimum version.
|
for _, part := range parts {
|
||||||
for i := range parts {
|
if _, err := strconv.Atoi(part); err != nil {
|
||||||
n, err := strconv.Atoi(parts[i])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
requiredN, err := strconv.Atoi(requiredParts[i])
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if n < requiredN {
|
// Once we've determined we have a proper version string of the format
|
||||||
return fmt.Errorf("version %v below minimum version "+
|
// major.minor.revision.build, we can just do a string comparison to
|
||||||
"supported %v", version, MinTorVersion)
|
// determine if it satisfies the minimum version supported.
|
||||||
}
|
if version < MinTorVersion {
|
||||||
|
return fmt.Errorf("version %v below minimum version supported "+
|
||||||
|
"%v", version, MinTorVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -28,6 +28,10 @@ func TestParseTorVersion(t *testing.T) {
|
|||||||
version: "0.4.3.6",
|
version: "0.4.3.6",
|
||||||
valid: true,
|
valid: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
version: "0.4.0.5",
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
version: "1.3.3.6",
|
version: "1.3.3.6",
|
||||||
valid: true,
|
valid: true,
|
||||||
@ -56,6 +60,10 @@ func TestParseTorVersion(t *testing.T) {
|
|||||||
version: "0.1.3.6",
|
version: "0.1.3.6",
|
||||||
valid: false,
|
valid: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
version: "0.0.6.3",
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user