Skip to content

Commit 438dbf3

Browse files
authored
evergreen: Fix app_key retrieval when creating the pref store (#9022)
Ensure the app_key buffer is properly sized before and after calling GetAppKey. Previously, std::string::reserve was used which allocated capacity but did not change the string's logical size. This leads to app_key being empty, causing the prefs store file name to be incorrect. Bug: 431862767
1 parent 8cacfce commit 438dbf3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cobalt/updater/prefs.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ std::unique_ptr<PrefService> CreatePrefService() {
4444
return nullptr;
4545
}
4646
std::string app_key;
47-
app_key.reserve(IM_EXT_MAX_APP_KEY_LENGTH);
48-
if (installation_api->GetAppKey(app_key.data(), app_key.capacity()) ==
47+
app_key.resize(IM_EXT_MAX_APP_KEY_LENGTH);
48+
if (installation_api->GetAppKey(app_key.data(), app_key.size()) ==
4949
IM_EXT_ERROR) {
5050
LOG(ERROR) << "Failed to get app key.";
5151
return nullptr;
5252
}
53+
app_key.resize(strlen(app_key.c_str()));
5354

5455
LOG(INFO) << "Updater: prefs app_key=" << app_key;
5556
PrefServiceFactory pref_service_factory;

0 commit comments

Comments
 (0)