@@ -2091,6 +2091,43 @@ def setVerbosity():
2091
2091
elif conf .verbose >= 5 :
2092
2092
logger .setLevel (CUSTOM_LOGGING .TRAFFIC_IN )
2093
2093
2094
+ def _normalizeOptions (inputOptions ):
2095
+ """
2096
+ Sets proper option types
2097
+ """
2098
+
2099
+ types_ = {}
2100
+ for group in optDict .keys ():
2101
+ types_ .update (optDict [group ])
2102
+
2103
+ for key in inputOptions :
2104
+ if key in types_ :
2105
+ value = inputOptions [key ]
2106
+ if value is None :
2107
+ continue
2108
+
2109
+ type_ = types_ [key ]
2110
+ if type_ and isinstance (type_ , tuple ):
2111
+ type_ = type_ [0 ]
2112
+
2113
+ if type_ == OPTION_TYPE .BOOLEAN :
2114
+ try :
2115
+ value = bool (value )
2116
+ except (TypeError , ValueError ):
2117
+ value = False
2118
+ elif type_ == OPTION_TYPE .INTEGER :
2119
+ try :
2120
+ value = int (value )
2121
+ except (TypeError , ValueError ):
2122
+ value = 0
2123
+ elif type_ == OPTION_TYPE .FLOAT :
2124
+ try :
2125
+ value = float (value )
2126
+ except (TypeError , ValueError ):
2127
+ value = 0.0
2128
+
2129
+ inputOptions [key ] = value
2130
+
2094
2131
def _mergeOptions (inputOptions , overrideOptions ):
2095
2132
"""
2096
2133
Merge command line options with configuration file and default options.
@@ -2102,6 +2139,7 @@ def _mergeOptions(inputOptions, overrideOptions):
2102
2139
if inputOptions .pickledOptions :
2103
2140
try :
2104
2141
inputOptions = base64unpickle (inputOptions .pickledOptions )
2142
+ _normalizeOptions (inputOptions )
2105
2143
except Exception , ex :
2106
2144
errMsg = "provided invalid value '%s' for option '--pickled-options'" % inputOptions .pickledOptions
2107
2145
errMsg += " ('%s')" % ex if ex .message else ""
@@ -2127,35 +2165,21 @@ def _mergeOptions(inputOptions, overrideOptions):
2127
2165
if hasattr (conf , key ) and conf [key ] is None :
2128
2166
conf [key ] = value
2129
2167
2130
- _ = {}
2131
- for key , value in os .environ .items ():
2132
- if key .upper ().startswith (SQLMAP_ENVIRONMENT_PREFIX ):
2133
- _ [key [len (SQLMAP_ENVIRONMENT_PREFIX ):].upper ()] = value
2134
2168
2135
- types_ = {}
2169
+ lut = {}
2136
2170
for group in optDict .keys ():
2137
- types_ .update (optDict [group ])
2138
-
2139
- for key in conf :
2140
- if key .upper () in _ and key in types_ :
2141
- value = _ [key .upper ()]
2171
+ lut .update ((_ .upper (), _ ) for _ in optDict [group ])
2142
2172
2143
- if types_ [key ] == OPTION_TYPE .BOOLEAN :
2144
- try :
2145
- value = bool (value )
2146
- except ValueError :
2147
- value = False
2148
- elif types_ [key ] == OPTION_TYPE .INTEGER :
2149
- try :
2150
- value = int (value )
2151
- except ValueError :
2152
- value = 0
2153
- elif types_ [key ] == OPTION_TYPE .FLOAT :
2154
- try :
2155
- value = float (value )
2156
- except ValueError :
2157
- value = 0.0
2173
+ envOptions = {}
2174
+ for key , value in os .environ .items ():
2175
+ if key .upper ().startswith (SQLMAP_ENVIRONMENT_PREFIX ):
2176
+ _ = key [len (SQLMAP_ENVIRONMENT_PREFIX ):].upper ()
2177
+ if _ in lut :
2178
+ envOptions [lut [_ ]] = value
2158
2179
2180
+ if envOptions :
2181
+ _normalizeOptions (envOptions )
2182
+ for key , value in envOptions .items ():
2159
2183
conf [key ] = value
2160
2184
2161
2185
mergedOptions .update (conf )
0 commit comments