Fix a heap-use-after-free in a unit test (#7230)

* Fix a heap-use-after-free in a unit test

The data passed to IAsyncFile::write must remain valid until the future
is ready.

* Use holdWhile instead of a new state variable
This commit is contained in:
Andrew Noyes 2022-06-07 14:48:01 -07:00 committed by GitHub
parent a0bb585260
commit 1997e6057c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -2706,8 +2706,8 @@ ACTOR Future<Void> updateNewestSoftwareVersion(std::string folder,
0600));
SWVersion swVersion(latestVersion, currentVersion, minCompatibleVersion);
auto s = swVersionValue(swVersion);
ErrorOr<Void> e = wait(errorOr(newVersionFile->write(s.toString().c_str(), s.size(), 0)));
Value s = swVersionValue(swVersion);
ErrorOr<Void> e = wait(holdWhile(s, errorOr(newVersionFile->write(s.begin(), s.size(), 0))));
if (e.isError()) {
throw e.getError();
}