Skip to content

Commit

Permalink
Add try/catch when reading upgrade codes to prevent larger user impac…
Browse files Browse the repository at this point in the history
…t than needed (#3637)
  • Loading branch information
JohnMcPMS committed Sep 19, 2023
1 parent 9ecbc52 commit 61dcd9c
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/AppInstallerRepositoryCore/Microsoft/ARPHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,39 @@ namespace AppInstaller::Repository::Microsoft
AICLI_LOG(Repo, Info, << "Reading MSI UpgradeCodes");
std::map<std::string, std::string> upgradeCodes;

// There is no UpgradeCodes key on the x86 view of the registry
Registry::Key upgradeCodesKey = Registry::Key::OpenIfExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes", 0, KEY_READ | KEY_WOW64_64KEY);

if (upgradeCodesKey)
try
{
for (const auto& upgradeCodeKeyRef : upgradeCodesKey)
// There is no UpgradeCodes key on the x86 view of the registry
Registry::Key upgradeCodesKey = Registry::Key::OpenIfExists(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UpgradeCodes", 0, KEY_READ | KEY_WOW64_64KEY);

if (upgradeCodesKey)
{
auto upgradeCode = TryUnpackUpgradeCodeGuid(upgradeCodeKeyRef.Name());
if (upgradeCode)
for (const auto& upgradeCodeKeyRef : upgradeCodesKey)
{
auto upgradeCodeKey = upgradeCodeKeyRef.Open();
for (const auto& productCodeValue : upgradeCodeKey.Values())
std::string keyName;

try
{
auto productCode = TryUnpackUpgradeCodeGuid(productCodeValue.Name());
if (productCode)
keyName = upgradeCodeKeyRef.Name();
auto upgradeCode = TryUnpackUpgradeCodeGuid(keyName);
if (upgradeCode)
{
upgradeCodes[*productCode] = *upgradeCode;
auto upgradeCodeKey = upgradeCodeKeyRef.Open();
for (const auto& productCodeValue : upgradeCodeKey.Values())
{
auto productCode = TryUnpackUpgradeCodeGuid(productCodeValue.Name());
if (productCode)
{
upgradeCodes[*productCode] = *upgradeCode;
}
}
}
}
CATCH_LOG_MSG("Failed to read upgrade code: %hs", keyName.c_str());
}
}
}
}
CATCH_LOG_MSG("Failed to read upgrade codes.");

return upgradeCodes;
}
Expand Down

0 comments on commit 61dcd9c

Please sign in to comment.