Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UNSAFE_TODO for wallet [part 2 of N] #26469

Merged
merged 4 commits into from
Nov 18, 2024
Merged

Conversation

supermassive
Copy link
Collaborator

@supermassive supermassive commented Nov 11, 2024

Resolves brave/brave-browser#42200

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@supermassive supermassive requested a review from a team as a code owner November 11, 2024 07:27
@supermassive supermassive changed the title Fix UNSAFE_TODO for wallet Fix UNSAFE_TODO for wallet [part 2 of N] Nov 11, 2024
Copy link
Collaborator

@cdesouza-chromium cdesouza-chromium left a comment

Choose a reason for hiding this comment

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

LGTM

if (type_split.size() != 2) {
return std::nullopt;
}
const std::string array_type = type_split[0];
auto array_type = type_split[0];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
auto array_type = type_split[0];
const auto array_type = type_split[0];

just a nit for it to be const std::string_view

Copy link
Contributor

[puLL-Merge] - brave/brave-core@26469

Description

This PR makes several changes to improve code quality, safety, and performance in the Brave Wallet component. The changes primarily focus on modernizing C++ usage, improving type safety, and optimizing memory operations.

Changes

Changes

  1. components/brave_wallet/browser/eip1559_transaction.cc and eip2930_transaction.cc:

    • Added #include "base/containers/to_vector.h"
    • Changed KeccakHash(result) to base::ToVector(KeccakHash(result))
  2. components/brave_wallet/browser/eth_abi_decoder.cc:

    • Removed #pragma allow_unsafe_buffers
    • Added #include "base/containers/span_reader.h"
    • Replaced several raw pointer and size-based operations with base::span and base::SpanReader
    • Optimized string operations using base::StrCat
  3. components/brave_wallet/browser/eth_abi_decoder.h:

    • Changed function signature to use base::span<const uint8_t> instead of const std::vector<uint8_t>&
  4. components/brave_wallet/browser/eth_allowance_manager.cc:

    • Changed KeccakHash usage to return a hex string directly
  5. components/brave_wallet/browser/eth_data_parser.cc:

    • Replaced vector slicing with base::span operations
  6. components/brave_wallet/browser/eth_transaction.cc:

    • Added #include "base/containers/to_vector.h"
    • Changed KeccakHash usage to return byte arrays instead of strings
  7. components/brave_wallet/browser/ethereum_keyring.cc:

    • Optimized string and vector operations using base::StrCat and base::Extend
  8. components/brave_wallet/browser/ethereum_provider_impl.cc:

    • Added #include "base/containers/to_vector.h"
    • Changed std::move(message_to_sign) to base::ToVector(message_to_sign)
  9. components/brave_wallet/browser/internal/hd_key.cc:

    • Optimized memory operations using base::span and base::ToVector
  10. components/brave_wallet/common/eth_address.cc and eth_address.h:

    • Replaced raw pointer operations with base::span
    • Optimized string operations using base::StrCat
  11. components/brave_wallet/common/eth_sign_typed_data_helper.cc and eth_sign_typed_data_helper.h:

    • Replaced std::vector<uint8_t> with custom Eip712HashArray type
    • Optimized string operations and memory usage
  12. components/brave_wallet/common/hash_utils.cc and hash_utils.h:

    • Introduced new types like KeccakHashArray and Ripemd160HashArray
    • Optimized hash functions to work with base::span
  13. components/brave_wallet/common/hex_utils.cc and hex_utils.h:

    • Removed redundant function overloads
    • Standardized on base::span for input parameters
  14. components/brave_wallet/common/zcash_utils.cc:

    • Optimized memory operations using base::span and base::Extend

Possible Issues

  • The changes to function signatures and return types may require updates in calling code not visible in this diff.
  • Some optimizations might affect performance in unexpected ways and should be benchmarked.

Security Hotspots

No significant security issues were identified in this change. The modifications generally improve type safety and reduce the risk of buffer overflows or misuse of raw pointers.

@supermassive supermassive merged commit af020d2 into master Nov 18, 2024
19 checks passed
@supermassive supermassive deleted the wallet_unsafe_todo_2 branch November 18, 2024 10:09
@github-actions github-actions bot added this to the 1.75.x - Nightly milestone Nov 18, 2024
@brave-builds
Copy link
Collaborator

Released in v1.75.27

kjozwiak pushed a commit that referenced this pull request Dec 6, 2024
* Merge pull request #26068 from brave/cr132

Upgrade from Chromium 131 to Chromium 132

* [Lit]: Migrate `brave-item-list-more-items` to Lit (#26493)

* [CodeHealth] Remove all uses of `NOTREACHED_NORETURN` (#26508)

This PR replaces all occurences of `NOTREACHED_NORETURN` with
`NOTREACHED`, since they are semantically identical.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/5a9d4c5aa85977fc711eb9c0ff1207c5ac1a0959

commit 5a9d4c5aa85977fc711eb9c0ff1207c5ac1a0959
Author: Peter Boström <[email protected]>
Date:   Tue Nov 12 01:38:46 2024 +0000

    Remove enable_log_error_not_reached

    This flag only applied to NOTREACHED_IN_MIGRATION() for ChromeOS which
    is on its way out.

    Bug: 40580068

* [CodeHealth] Drop `proc-macro-error` from `filecoin-cxx` (#26427)

* [CodeHealth] Drop `proc-macro-error` from `filecoin-cxx`

This PR updates all crates around `multihash` to use the latest
`multihash` version that does not depend anymore on `proc-macro-error`.
This crate is being removed as it is getting flagged in security audits
for being unmaintained, and it also relies on unstable rustc features.

* [rust] `gnrt` crate changes for `multihash` v.0.19

This commit includes all the mechanical changes done by `gnrt`.

* Fix UNSAFE_TODO for wallet [part 2 of N] (#26469)

* [CodeHealth] Fix dangling span references (#26461)

This PR fixes cases where a local constant is being used to initialise a
`span` but then the span is being used by the time the local has already
been discarded. This is undefined behaviour although in both cases it
seems to be incidently working.

Resolve brave/brave-browser#42185

* [CodeHealth] Normalise `const` declaration pt.1 (#26714)

This PR is part of a couple of rewrites to be carried out normalising
the cases where we have constant declaration. In this PR we have the
following fixes:

 - Remove redundant `const` qualifier alongside `constexpr`
 - Function-scope constants as `static constexpr`
 - Remove the use of `extern` declarations
 - Whenever possible use `constexpr`
 - When appropriate, use `MakeFixedFlatSet`.

These changes are in conformance with some upcoming clarified guidelines.
Furthermore, this takes us one step closer to have some automation for
clang-tidy, as right now there are too many clang-tidy warnings around
constant/variable naming.

Resolves brave/brave-browser#42490

* [CodeHealth] Remove all uses of `NOTREACHED_NORETURN` (#26508)

This PR replaces all occurences of `NOTREACHED_NORETURN` with
`NOTREACHED`, since they are semantically identical.

Chromium change:
https://chromium.googlesource.com/chromium/src/+/5a9d4c5aa85977fc711eb9c0ff1207c5ac1a0959

commit 5a9d4c5aa85977fc711eb9c0ff1207c5ac1a0959
Author: Peter Boström <[email protected]>
Date:   Tue Nov 12 01:38:46 2024 +0000

    Remove enable_log_error_not_reached

    This flag only applied to NOTREACHED_IN_MIGRATION() for ChromeOS which
    is on its way out.

    Bug: 40580068

* [Lit]: Update ExtensionsToolbarElement override (#26492)

* [NOTREACHED]: Migrate a bunch of `NOTREACHED_IN_MIGRATIONS` (#26412)

* [NOTREACHED]: Update OpenBraveVPNUrls

* [NOTREACHED]: Update ParseFeedItems

* [NOTREACHED]: Migrate GenerateAllFeed

* [NOTREACHED]: Migrate MdTextButton

* [NOTREACHED]: Migrate NTPBackgroundPrefs

* [NOTREACHED]: Migrate brave_app_menu_model

* [NOTREACHED]: Migrate b/u/tabs

* [NOTREACHED]: b/u/v/frame

* [NOTREACHED]: b/b/themes

* Replaced NOTREACHED_IN_MIGRATION for Brave Sync code (#26391)

* Replaced NOTREACHED_IN_MIGRATION for Brave Sync code

* [DanglingPtr] Remove `ProfileMenuViewBase` patching (#26499)

This patch was introduced as a temporary measure to allow switching on
the dangling pointer detector.

This PR fixes the two dangling pointers in `ProfileMenuViewBase` by
avoiding calling `SetProfileIdentityInfo` more than once, and actually
overriding it, so the first call to the `SetProfileIdentityInfo` can be
given the correct arguments.

One test had to be disabled, as it was not actually testing the way the
profile menu viewer was being instantiated. The way brave does it
requires to consult theme data, which is not available for this
particular test.

Resolves brave/brave-browser#42231

* Disable screen_ai component download/installation (#26167)

* Disable screen_ai component download/installation

* Disable upstream OCR integration

---------

Co-authored-by: Anthony Tseng <[email protected]>

* Fix unused variables warnings at java (#26433)

* Removed unused variables and members at Brave java files

* [DanglingPtr] Fix `WebUIBubbleManagerImpl` dangling patch (#26465)

A patch was added to `WebUIBubbleManagerImpl` when enabling the dangling
pointer detector on Linux, as a temporary measure. This change corrects
the the underlying issue requiring this pointer to be marked as
dangling.

This particular dangling pointer occurred because the toolbar view was
being passed as the achor for this browser data bubbles, the toolbar
gets destroyed prior to these browser data bubbles being disposed. This
PR adds checks during in the `BraveBrowserView` dtor, to make sure there
are no dangling references to the toolbar view by the time the
termination is cleaning up browser data.

Resolves brave/brave-browser#42196

* Merge pull request #26829 from brave/cr132-followup-add-aida-client-unittest

Add unit test to ensure that AidaClient remains disabled

* Upgrade from Chromium 132.0.6834.15 to Chromium 132.0.6834.33

Update pins list timestamp

Updated strings for Chromium 132.0.6834.33

* Merge pull request #26864 from brave/cr132-followup-fix-broken-tab-group-menu-options

Fix broken tab group menu options

---------

Co-authored-by: Jay Harris <[email protected]>
Co-authored-by: cdesouza-chromium <[email protected]>
Co-authored-by: Anton Paymyshev <[email protected]>
Co-authored-by: AlexeyBarabash <[email protected]>
Co-authored-by: Anthony Tseng <[email protected]>
Co-authored-by: brave-builds <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix -Wunsafe-buffer-usage exclusions for wallet files [2/N]
5 participants