mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-19 15:54:52 +01:00
Count "0" as a positive integer
This commit is contained in:
@@ -226,18 +226,21 @@ public class VulnerableSoftware extends IndexEntry implements Serializable, Comp
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the string passed in is a positive integer.
|
* Determines if the string passed in is a positive integer.
|
||||||
|
* To be counted as a positive integer, the string must only contain 0-9
|
||||||
|
* and must not have any leading zeros (though "0" is a valid positive
|
||||||
|
* integer).
|
||||||
*
|
*
|
||||||
* @param str the string to test
|
* @param str the string to test
|
||||||
* @return true if the string only contains 0-9, otherwise false.
|
* @return true if the string only contains 0-9, otherwise false.
|
||||||
*/
|
*/
|
||||||
private static boolean isPositiveInteger(final String str) {
|
static boolean isPositiveInteger(final String str) {
|
||||||
if (str == null || str.isEmpty()) {
|
if (str == null || str.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// numbers/versions with leading zeros should not be treated as numbers
|
// numbers with leading zeros should not be treated as numbers
|
||||||
// (e.g. when comparing "01" <-> "1")
|
// (e.g. when comparing "01" <-> "1")
|
||||||
if (str.charAt(0) == '0') {
|
if (str.charAt(0) == '0' && str.length() > 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,6 +109,10 @@ public class VulnerableSoftwareTest extends BaseTest {
|
|||||||
vs1.setCpe("2.1.10");
|
vs1.setCpe("2.1.10");
|
||||||
assertTrue(vs.compareTo(vs1) < 0);
|
assertTrue(vs.compareTo(vs1) < 0);
|
||||||
|
|
||||||
|
vs.setCpe("2.1.42");
|
||||||
|
vs1.setCpe("2.3.21");
|
||||||
|
assertTrue(vs.compareTo(vs1) < 0);
|
||||||
|
|
||||||
vs.setCpe("cpe:/a:hp:system_management_homepage:2.1.1");
|
vs.setCpe("cpe:/a:hp:system_management_homepage:2.1.1");
|
||||||
vs1.setCpe("cpe:/a:hp:system_management_homepage:2.1.10");
|
vs1.setCpe("cpe:/a:hp:system_management_homepage:2.1.10");
|
||||||
assertTrue(vs.compareTo(vs1) < 0);
|
assertTrue(vs.compareTo(vs1) < 0);
|
||||||
@@ -129,6 +133,10 @@ public class VulnerableSoftwareTest extends BaseTest {
|
|||||||
vs.setCpe("cpe:/a:ibm:security_guardium_database_activity_monitor:10.01");
|
vs.setCpe("cpe:/a:ibm:security_guardium_database_activity_monitor:10.01");
|
||||||
vs1.setCpe("cpe:/a:ibm:security_guardium_database_activity_monitor:10.1");
|
vs1.setCpe("cpe:/a:ibm:security_guardium_database_activity_monitor:10.1");
|
||||||
assertTrue(vs.compareTo(vs1) < 0);
|
assertTrue(vs.compareTo(vs1) < 0);
|
||||||
|
|
||||||
|
vs.setCpe("2.0");
|
||||||
|
vs1.setCpe("2.1");
|
||||||
|
assertTrue(vs.compareTo(vs1) < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -152,4 +160,18 @@ public class VulnerableSoftwareTest extends BaseTest {
|
|||||||
assertEquals("mysql", vs.getProduct());
|
assertEquals("mysql", vs.getProduct());
|
||||||
assertEquals("5.1.23a", vs.getVersion());
|
assertEquals("5.1.23a", vs.getVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIspositiveInteger() {
|
||||||
|
assertTrue(VulnerableSoftware.isPositiveInteger("1"));
|
||||||
|
assertTrue(VulnerableSoftware.isPositiveInteger("10"));
|
||||||
|
assertTrue(VulnerableSoftware.isPositiveInteger("666"));
|
||||||
|
assertTrue(VulnerableSoftware.isPositiveInteger("0"));
|
||||||
|
|
||||||
|
assertFalse(VulnerableSoftware.isPositiveInteger("+1"));
|
||||||
|
assertFalse(VulnerableSoftware.isPositiveInteger("-1"));
|
||||||
|
assertFalse(VulnerableSoftware.isPositiveInteger("2.1"));
|
||||||
|
assertFalse(VulnerableSoftware.isPositiveInteger("01"));
|
||||||
|
assertFalse(VulnerableSoftware.isPositiveInteger("00"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user