|
12 | 12 | import collections |
13 | 13 | import contextlib |
14 | 14 | import copy |
15 | | -import distutils |
16 | 15 | import functools |
17 | 16 | import getpass |
18 | 17 | import hashlib |
|
176 | 175 | from lib.core.settings import URLENCODE_CHAR_LIMIT |
177 | 176 | from lib.core.settings import URLENCODE_FAILSAFE_CHARS |
178 | 177 | from lib.core.settings import USER_AGENT_ALIASES |
| 178 | +from lib.core.settings import VERSION_COMPARISON_CORRECTION |
179 | 179 | from lib.core.settings import VERSION_STRING |
180 | 180 | from lib.core.settings import ZIP_HEADER |
181 | 181 | from lib.core.settings import WEBSCARAB_SPLITTER |
@@ -517,15 +517,15 @@ def getIdentifiedDbms(): |
517 | 517 |
|
518 | 518 | @staticmethod |
519 | 519 | def getVersion(): |
520 | | - versions = filterNone(flattenValue(kb.dbmsVersion)) |
| 520 | + versions = filterNone(flattenValue(kb.dbmsVersion)) if not isinstance(kb.dbmsVersion, six.string_types) else [kb.dbmsVersion] |
521 | 521 | if not isNoneValue(versions): |
522 | 522 | return versions[0] |
523 | 523 | else: |
524 | 524 | return None |
525 | 525 |
|
526 | 526 | @staticmethod |
527 | 527 | def getVersionList(): |
528 | | - versions = filterNone(flattenValue(kb.dbmsVersion)) |
| 528 | + versions = filterNone(flattenValue(kb.dbmsVersion)) if not isinstance(kb.dbmsVersion, six.string_types) else [kb.dbmsVersion] |
529 | 529 | if not isNoneValue(versions): |
530 | 530 | return versions |
531 | 531 | else: |
@@ -3110,37 +3110,63 @@ def filterNone(values): |
3110 | 3110 |
|
3111 | 3111 | return retVal |
3112 | 3112 |
|
3113 | | -def isDBMSVersionAtLeast(version): |
| 3113 | +def isDBMSVersionAtLeast(minimum): |
3114 | 3114 | """ |
3115 | 3115 | Checks if the recognized DBMS version is at least the version specified |
| 3116 | +
|
| 3117 | + >>> pushValue(kb.dbmsVersion) |
| 3118 | + >>> kb.dbmsVersion = "2" |
| 3119 | + >>> isDBMSVersionAtLeast("1.3.4.1.4") |
| 3120 | + True |
| 3121 | + >>> isDBMSVersionAtLeast(2.1) |
| 3122 | + False |
| 3123 | + >>> isDBMSVersionAtLeast(">2") |
| 3124 | + False |
| 3125 | + >>> isDBMSVersionAtLeast(">=2.0") |
| 3126 | + True |
| 3127 | + >>> kb.dbmsVersion = "<2" |
| 3128 | + >>> isDBMSVersionAtLeast("2") |
| 3129 | + False |
| 3130 | + >>> isDBMSVersionAtLeast("1.5") |
| 3131 | + True |
| 3132 | + >>> kb.dbmsVersion = popValue() |
3116 | 3133 | """ |
3117 | 3134 |
|
3118 | 3135 | retVal = None |
3119 | 3136 |
|
3120 | | - if Backend.getVersion() and Backend.getVersion() != UNKNOWN_DBMS_VERSION: |
3121 | | - value = Backend.getVersion().replace(" ", "").rstrip('.') |
| 3137 | + if not any(isNoneValue(_) for _ in (Backend.getVersion(), minimum)) and Backend.getVersion() != UNKNOWN_DBMS_VERSION: |
| 3138 | + version = Backend.getVersion().replace(" ", "").rstrip('.') |
3122 | 3139 |
|
3123 | | - while True: |
3124 | | - index = value.find('.', value.find('.') + 1) |
| 3140 | + if '.' in version: |
| 3141 | + parts = version.split('.', 1) |
| 3142 | + parts[1] = filterStringValue(parts[1], '[0-9]') |
| 3143 | + version = '.'.join(parts) |
3125 | 3144 |
|
3126 | | - if index > -1: |
3127 | | - value = value[0:index] + value[index + 1:] |
3128 | | - else: |
3129 | | - break |
| 3145 | + correction = 0.0 |
| 3146 | + if ">=" in version: |
| 3147 | + pass |
| 3148 | + elif '>' in version: |
| 3149 | + correction = VERSION_COMPARISON_CORRECTION |
| 3150 | + elif '<' in version: |
| 3151 | + correction = -VERSION_COMPARISON_CORRECTION |
3130 | 3152 |
|
3131 | | - value = filterStringValue(value, '[0-9.><=]') |
| 3153 | + version = float(filterStringValue(version, '[0-9.]')) + correction |
3132 | 3154 |
|
3133 | | - if value and isinstance(value, six.string_types): |
3134 | | - if value.startswith(">="): |
3135 | | - value = float(value.replace(">=", "")) |
3136 | | - elif value.startswith(">"): |
3137 | | - value = float(value.replace(">", "")) + 0.01 |
3138 | | - elif value.startswith("<="): |
3139 | | - value = float(value.replace("<=", "")) |
3140 | | - elif value.startswith(">"): |
3141 | | - value = float(value.replace("<", "")) - 0.01 |
3142 | | - |
3143 | | - retVal = distutils.version.LooseVersion(getUnicode(value)) >= distutils.version.LooseVersion(getUnicode(version)) |
| 3155 | + if isinstance(minimum, six.string_types): |
| 3156 | + if '.' in minimum: |
| 3157 | + parts = minimum.split('.', 1) |
| 3158 | + parts[1] = filterStringValue(parts[1], '[0-9]') |
| 3159 | + minimum = '.'.join(parts) |
| 3160 | + |
| 3161 | + correction = 0.0 |
| 3162 | + if minimum.startswith(">="): |
| 3163 | + pass |
| 3164 | + elif minimum.startswith(">"): |
| 3165 | + correction = VERSION_COMPARISON_CORRECTION |
| 3166 | + |
| 3167 | + minimum = float(filterStringValue(minimum, '[0-9.]')) + correction |
| 3168 | + |
| 3169 | + retVal = version >= minimum |
3144 | 3170 |
|
3145 | 3171 | return retVal |
3146 | 3172 |
|
|
0 commit comments