Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@yaakovschectman
Copy link
Contributor

StreamHandlerError previously took references to its parameters, which means if the error persists longer than its calling scope, it may point to nonexistent values and crash the program. Change the constructor to take the string parameters as value rather than reference, and take its details as a unique_ptr rather than a raw pointer. flutter/flutter#101682 (comment) suggests that existing projects only ever pass nullptr to this parameter, so changing to a unique_ptr will not break them.

The details field is potentially passed to EncodeErrorEnvelopeInternal. Our implementations of this abstract method in the standard and json codecs copy the value pointed to by the parameter, so passing the raw pointer behind the unique pointer should not lead to dangling pointers.

flutter/flutter#101682

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide and the C++, Objective-C, Java style guides.
  • I listed at least one issue that this PR fixes in the description above.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Comment on lines +8 to +9
#include <memory>
#include <string>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't break if this header file is imported before/without these imports.

result = codec->EncodeErrorEnvelope(error->error_code,
error->error_message,
error->error_details);
error->error_details.get());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method points to an abstract method that we implement in the standard and json codecs, both of which copy the value pointed to by the parameter.

Comment on lines 281 to 283
std::string code = "Code";
std::string msg = "Message";
std::unique_ptr<EncodableValue> details = std::make_unique<EncodableValue>("Details");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Declare these inside a nested scope so they are out of scope before our asserts, to test pass-by-value.

@yaakovschectman yaakovschectman marked this pull request as ready for review March 15, 2023 17:39
Copy link
Member

@loic-sharma loic-sharma left a comment

Choose a reason for hiding this comment

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

LGTM but please also get an approval from Stuart

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with one added test.

flutter/flutter#101682 (comment) suggests that existing projects only ever pass nullptr to this parameter, so changing to a unique_ptr will not break them.

Fingers crossed that this is still true. (If there's significant unexpected fallout we may have to revert and figure out another plan.)

std::unique_ptr<EncodableValue> details =
std::make_unique<EncodableValue>("Details");
error =
std::make_unique<StreamHandlerError<>>(code, msg, std::move(details));
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a second test that does a (code, msg, nullptr) so that we're absolutely certain that we aren't breaking that existing-in-the-wild pattern.

Copy link
Member

@cbracken cbracken left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for fixing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants