Skip to content

gui: Fix proxy setting options dialog crash#11809

Merged
laanwj merged 1 commit intobitcoin:masterfrom
laanwj:2017_12_gui_proxy_robustness
Dec 7, 2017
Merged

gui: Fix proxy setting options dialog crash#11809
laanwj merged 1 commit intobitcoin:masterfrom
laanwj:2017_12_gui_proxy_robustness

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Dec 1, 2017

This fixes a crash bug when opening the options dialog.

  • Check the return value of split() to avoid segmentation faults due to out of bounds when the user manages to enter invalid proxy settings. This is reported resonably often.

  • Move the default proxy/port to a constant instead of hardcoding magic values.

  • Factor out some common code.

  • Revert [gui] reset addrProxy/addrSeparateProxyTor if colon char missing #11448 because this proves a more robust replacement, it is no longer necessary and didn't generally solve the issue.

No attempt is made to do full sanity checking on the proxy, so it can still be rejected by the core with an InitError message.

@laanwj laanwj added the GUI label Dec 1, 2017
Copy link
Contributor

@gmaxwell gmaxwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 76755055e038d06ce1f3c69a6e9a2bab4625507b

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put this in the same place as DEFAULT_GUI_PROXY_PORT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there, just not the value.
Strings are pointers which point into a .rodata segment, so need to be present in a compilation unit.
Defining string constants in header files is a bad idea because it causes duplication in every place it's used, or even can lead to linker conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove SkipEmptyParts? Should foobar::1234 be valid?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also validate port is numeric?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally (see the OP) do not add any extra validation in this pull. All that this does is prevent the crash.
A non-numeric port will already cause an init error with a message that the proxy is invalid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting is invalid, maybe log/warn?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Invalid proxy settings already cause an error at a different level (e.g. -proxy=). I don't want to duplicate validation and parsing logic.
(also it's out of scope of this pull, which is just a bugfix/cleanup)

@promag
Copy link
Contributor

promag commented Dec 4, 2017

utACK 7675505.

This fixes a crash bug when opening the options dialog.

- Check the return value of split() to avoid segmentation faults due to
  out of bounds when the user manages to enter invalid proxy settings.
  This is reported resonably often.

- Move the default proxy/port to a constant instead of hardcoding magic
  values.

- Factor out some common code.

- Revert bitcoin#11448 because this proves a more robust replacement, it is no
  longer necessary and didn't generally solve the issue.

No attempt is made to do full sanity checking on the proxy, so it can
still be rejected by the core with an InitError message.
@laanwj
Copy link
Member Author

laanwj commented Dec 7, 2017

squashed efcd4cd 7f434d0 415cd45 7675505 to f05d349

@laanwj laanwj force-pushed the 2017_12_gui_proxy_robustness branch from 7675505 to f05d349 Compare December 7, 2017 16:34
@laanwj laanwj merged commit f05d349 into bitcoin:master Dec 7, 2017
laanwj added a commit that referenced this pull request Dec 7, 2017
f05d349 gui: Fix proxy setting options dialog crash (Wladimir J. van der Laan)

Pull request description:

  This fixes a crash bug when opening the options dialog.

  - Check the return value of split() to avoid segmentation faults due to   out of bounds when the user manages to enter invalid proxy settings.  This is reported resonably often.

  - Move the default proxy/port to a constant instead of hardcoding magic values.

  - Factor out some common code.

  - Revert #11448 because this proves a more robust replacement, it is no longer necessary and didn't generally solve the issue.

  No attempt is made to do full sanity checking on the proxy, so it can still be rejected by the core with an InitError message.

Tree-SHA512: 72b700b7d6c4d3e3410f0c60e9e4facf93d7c6c1a1b6b23957c48b074a045970f518166952859d1ebca8620062cb70d222670a7310bbd6fe50550ec6d04417b5
@promag
Copy link
Contributor

promag commented Dec 7, 2017

👍

@Willtech
Copy link
Contributor

Willtech commented Feb 27, 2018

In v0.16.0rc4 on Windows-64 executable bitcoin-qt.exe, the default proxy port is %2 ?

I might suggest, if it is empty or not-a-valid-number, then just set the port to 9050.

Also, the warning to restart client for changes to be effective does not seem to be displayed consistently, if the client needed to be restarted for any change.

@maflcko
Copy link
Member

maflcko commented Mar 17, 2018

Tagged for backport to 15.2 if we want that, but please also backport #12650, which fixes another bug in this code.

@laanwj laanwj removed this from the 0.15.2 milestone May 24, 2018
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 27, 2020
f05d349 gui: Fix proxy setting options dialog crash (Wladimir J. van der Laan)

Pull request description:

  This fixes a crash bug when opening the options dialog.

  - Check the return value of split() to avoid segmentation faults due to   out of bounds when the user manages to enter invalid proxy settings.  This is reported resonably often.

  - Move the default proxy/port to a constant instead of hardcoding magic values.

  - Factor out some common code.

  - Revert bitcoin#11448 because this proves a more robust replacement, it is no longer necessary and didn't generally solve the issue.

  No attempt is made to do full sanity checking on the proxy, so it can still be rejected by the core with an InitError message.

Tree-SHA512: 72b700b7d6c4d3e3410f0c60e9e4facf93d7c6c1a1b6b23957c48b074a045970f518166952859d1ebca8620062cb70d222670a7310bbd6fe50550ec6d04417b5
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants