Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: chrome/installer/util/shell_util.cc

Issue 2963783002: Remove unsafe registry APIs from base::win::RegKey
Patch Set: half-fix remoting Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This file defines functions that integrate Chrome in Windows shell. These 5 // This file defines functions that integrate Chrome in Windows shell. These
6 // functions can be used by Chrome as well as Chrome installer. All of the 6 // functions can be used by Chrome as well as Chrome installer. All of the
7 // work is done by the local functions defined in anonymous namespace in 7 // work is done by the local functions defined in anonymous namespace in
8 // this class. 8 // this class.
9 9
10 #include "chrome/installer/util/shell_util.h" 10 #include "chrome/installer/util/shell_util.h"
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 base::FilePath exe_path = chrome_exe.DirName().Append(installer::kSetupExe); 697 base::FilePath exe_path = chrome_exe.DirName().Append(installer::kSetupExe);
698 698
699 // Failing that, read the path to setup.exe from Chrome's ClientState key, 699 // Failing that, read the path to setup.exe from Chrome's ClientState key,
700 // which is the canonical location of the installer for all types of installs 700 // which is the canonical location of the installer for all types of installs
701 // (see AddUninstallShortcutWorkItems). 701 // (see AddUninstallShortcutWorkItems).
702 const bool is_per_user = InstallUtil::IsPerUserInstall(); 702 const bool is_per_user = InstallUtil::IsPerUserInstall();
703 if (!base::PathExists(exe_path)) { 703 if (!base::PathExists(exe_path)) {
704 RegKey key(is_per_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, 704 RegKey key(is_per_user ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
705 dist->GetStateKey().c_str(), KEY_QUERY_VALUE | KEY_WOW64_32KEY); 705 dist->GetStateKey().c_str(), KEY_QUERY_VALUE | KEY_WOW64_32KEY);
706 base::string16 uninstall_string; 706 base::string16 uninstall_string;
707 if (key.ReadValue(installer::kUninstallStringField, &uninstall_string) == 707 if (key.Valid() && key.ReadValue(installer::kUninstallStringField,
708 ERROR_SUCCESS) { 708 &uninstall_string) == ERROR_SUCCESS) {
709 exe_path = base::FilePath(uninstall_string); 709 exe_path = base::FilePath(uninstall_string);
710 } 710 }
711 } 711 }
712 712
713 if (base::PathExists(exe_path)) { 713 if (base::PathExists(exe_path)) {
714 base::CommandLine cmd(exe_path); 714 base::CommandLine cmd(exe_path);
715 InstallUtil::AppendModeSwitch(&cmd); 715 InstallUtil::AppendModeSwitch(&cmd);
716 if (!is_per_user) 716 if (!is_per_user)
717 cmd.AppendSwitch(installer::switches::kSystemLevel); 717 cmd.AppendSwitch(installer::switches::kSystemLevel);
718 cmd.AppendSwitchPath(installer::switches::kRegisterChromeBrowser, 718 cmd.AppendSwitchPath(installer::switches::kRegisterChromeBrowser,
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 // ProgId registrations are allowed to reside in HKCU for user-level installs 842 // ProgId registrations are allowed to reside in HKCU for user-level installs
843 // (and values there have priority over values in HKLM). The same is true for 843 // (and values there have priority over values in HKLM). The same is true for
844 // shell integration entries as of Windows 8. 844 // shell integration entries as of Windows 8.
845 if (confirmation_level == CONFIRM_PROGID_REGISTRATION || 845 if (confirmation_level == CONFIRM_PROGID_REGISTRATION ||
846 (confirmation_level == CONFIRM_SHELL_REGISTRATION && 846 (confirmation_level == CONFIRM_SHELL_REGISTRATION &&
847 base::win::GetVersion() >= base::win::VERSION_WIN8)) { 847 base::win::GetVersion() >= base::win::VERSION_WIN8)) {
848 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE); 848 const RegKey key_hkcu(HKEY_CURRENT_USER, reg_key.c_str(), KEY_QUERY_VALUE);
849 base::string16 hkcu_value; 849 base::string16 hkcu_value;
850 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|. 850 // If |reg_key| is present in HKCU, assert that it points to |chrome_exe|.
851 // Otherwise, fall back on an HKLM lookup below. 851 // Otherwise, fall back on an HKLM lookup below.
852 if (key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS) 852 if (key_hkcu.Valid() &&
853 key_hkcu.ReadValue(L"", &hkcu_value) == ERROR_SUCCESS)
853 return InstallUtil::ProgramCompare(chrome_exe).Evaluate(hkcu_value); 854 return InstallUtil::ProgramCompare(chrome_exe).Evaluate(hkcu_value);
854 } 855 }
855 856
856 // Assert that |reg_key| points to |chrome_exe| in HKLM. 857 // Assert that |reg_key| points to |chrome_exe| in HKLM.
857 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE); 858 const RegKey key_hklm(HKEY_LOCAL_MACHINE, reg_key.c_str(), KEY_QUERY_VALUE);
858 base::string16 hklm_value; 859 base::string16 hklm_value;
859 if (key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS) 860 if (key_hklm.Valid() && key_hklm.ReadValue(L"", &hklm_value) == ERROR_SUCCESS)
860 return InstallUtil::ProgramCompare(chrome_exe).Evaluate(hklm_value); 861 return InstallUtil::ProgramCompare(chrome_exe).Evaluate(hklm_value);
861 return false; 862 return false;
862 } 863 }
863 864
864 // Sets |suffix| to a 27 character string that is specific to this user on this 865 // Sets |suffix| to a 27 character string that is specific to this user on this
865 // machine (on user-level installs only). 866 // machine (on user-level installs only).
866 // To support old-style user-level installs however, |suffix| is cleared if the 867 // To support old-style user-level installs however, |suffix| is cleared if the
867 // user currently owns the non-suffixed HKLM registrations. 868 // user currently owns the non-suffixed HKLM registrations.
868 // |suffix| can also be set to the user's username if the current install is 869 // |suffix| can also be set to the user's username if the current install is
869 // suffixed as per the old-style registrations. 870 // suffixed as per the old-style registrations.
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2354 for (const auto& entry : entries) 2355 for (const auto& entry : entries)
2355 entry->AddToWorkItemList(root, items.get()); 2356 entry->AddToWorkItemList(root, items.get());
2356 2357
2357 // Apply all the registry changes and if there is a problem, rollback 2358 // Apply all the registry changes and if there is a problem, rollback
2358 if (!items->Do()) { 2359 if (!items->Do()) {
2359 items->Rollback(); 2360 items->Rollback();
2360 return false; 2361 return false;
2361 } 2362 }
2362 return true; 2363 return true;
2363 } 2364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698