@@ -2091,6 +2091,43 @@ def setVerbosity():
20912091 elif conf .verbose >= 5 :
20922092 logger .setLevel (CUSTOM_LOGGING .TRAFFIC_IN )
20932093
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+
20942131def _mergeOptions (inputOptions , overrideOptions ):
20952132 """
20962133 Merge command line options with configuration file and default options.
@@ -2102,6 +2139,7 @@ def _mergeOptions(inputOptions, overrideOptions):
21022139 if inputOptions .pickledOptions :
21032140 try :
21042141 inputOptions = base64unpickle (inputOptions .pickledOptions )
2142+ _normalizeOptions (inputOptions )
21052143 except Exception , ex :
21062144 errMsg = "provided invalid value '%s' for option '--pickled-options'" % inputOptions .pickledOptions
21072145 errMsg += " ('%s')" % ex if ex .message else ""
@@ -2127,35 +2165,21 @@ def _mergeOptions(inputOptions, overrideOptions):
21272165 if hasattr (conf , key ) and conf [key ] is None :
21282166 conf [key ] = value
21292167
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
21342168
2135- types_ = {}
2169+ lut = {}
21362170 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 ])
21422172
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
21582179
2180+ if envOptions :
2181+ _normalizeOptions (envOptions )
2182+ for key , value in envOptions .items ():
21592183 conf [key ] = value
21602184
21612185 mergedOptions .update (conf )
0 commit comments