Skip to content

Commit

Permalink
[CommCoreModule] capture primitive parameter by value
Browse files Browse the repository at this point in the history
Summary:
Fixes regression introduced in D8887.

This is a solution for [ENG-4926](https://linear.app/comm/issue/ENG-4926/client-backup-upload-issue).

When the code gets to run, the outer function `generateRandomString` may have already returned. This means that `size` might have been destroyed, and there is an undefined reference. That's why this function generates `backupID` with length 0 and as an effect causes `Argon2` to throw `salt too short`.

On dev everything worked, everything happens only on prod when code is more optimized.

I also added casting to the correct type.

Test Plan: Test upload protocol in `Release mode`.

Reviewers: michal, bartek, marcin, tomek

Reviewed By: bartek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D9197
  • Loading branch information
xsanm committed Sep 14, 2023
1 parent d583b31 commit 798e359
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,13 @@ jsi::Value CommCoreModule::computeBackupKey(

jsi::Value CommCoreModule::generateRandomString(jsi::Runtime &rt, double size) {
return createPromiseAsJSIValue(
rt,
[this, &size](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [this, &innerRt, &size, promise]() {
rt, [=](jsi::Runtime &innerRt, std::shared_ptr<Promise> promise) {
taskType job = [=, &innerRt]() {
std::string error;
std::string randomString;
try {
randomString = crypto::Tools::generateRandomString(size);
randomString =
crypto::Tools::generateRandomString(static_cast<size_t>(size));
} catch (const std::exception &e) {
error = "Failed to generate random string for size " +
std::to_string(size) + ": " + e.what();
Expand Down

0 comments on commit 798e359

Please sign in to comment.