python / cpython

The Python programming language
https://www.python.org
Other
62.37k stars 29.96k forks source link

[urllib] proxy_bypass_registry doesn't handle invalid proxy override values #82081

Open 2ebc7daf-8c44-49a8-b473-8de15ca5b8e9 opened 5 years ago

2ebc7daf-8c44-49a8-b473-8de15ca5b8e9 commented 5 years ago
BPO 37900
Nosy @pfmoore, @tjguk, @zware, @zooba, @kainjow

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields: ```python assignee = None closed_at = None created_at = labels = ['3.7', 'OS-windows', 'type-crash'] title = "[urllib] proxy_bypass_registry doesn't handle invalid proxy override values" updated_at = user = 'https://github.com/kainjow' ``` bugs.python.org fields: ```python activity = actor = 'kwojniak_box' assignee = 'none' closed = False closed_date = None closer = None components = ['Windows'] creation = creator = 'kwojniak_box' dependencies = [] files = [] hgrepos = [] issue_num = 37900 keywords = [] message_count = 1.0 messages = ['350038'] nosy_count = 5.0 nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'steve.dower', 'kwojniak_box'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'open' superseder = None type = 'crash' url = 'https://bugs.python.org/issue37900' versions = ['Python 2.7', 'Python 3.7'] ```

2ebc7daf-8c44-49a8-b473-8de15ca5b8e9 commented 5 years ago

proxy_bypass_registry() will split the ProxyOverride registry key by semicolon. Then for each value it uses that value as a regular expression pattern with match(). However, if this value is not a valid regular expression, then match() will throw an exception that goes uncaught. This then breaks the loop and prevents the function from working correctly on other valid input.

It's easy to reproduce:

  1. Set this registry key to 1 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyEnable
  2. Set HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ProxyOverride to this value (create as a string if necessary): []-78;
  3. Call urllib.proxy_bypass()

My suggestion for a fix would be to catch exceptions from match() in the loop and continue the loop on error.