Repository: electron/electron
File: shell/browser/browser_win.cc (C++)

Code before:
            .GetProgram();
  }

  if (!lookup_exe_path.empty()) {
    while (it->Valid()) {
      base::CommandLine registry_launch_cmd =
          base::CommandLine::FromString(it->Value());
      base::FilePath registry_launch_path = registry_launch_cmd.GetProgram();
      bool exe_match = base::FilePath::CompareEqualIgnoreCase(
          lookup_exe_path.value(), registry_launch_path.value());

      // add launch item to vector if it has a matching path (case-insensitive)
      if (exe_match) {
        LaunchItem launch_item;
        launch_item.name = it->Name();
        launch_item.path = registry_launch_path.value();
        launch_item.args = registry_launch_cmd.GetArgs();
        launch_item.scope = scope;
        launch_item.enabled = true;

        // attempt to update launch_item.enabled if there is a matching key
        // value entry in the StartupApproved registry
        HKEY hkey;
        // StartupApproved registry path
        LPCTSTR path = TEXT(
            "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApp"
            "roved\\Run");
        LONG res;
        if (scope == L"user") {
          res =
              RegOpenKeyEx(HKEY_CURRENT_USER, path, 0, KEY_QUERY_VALUE, &hkey);
        } else {
          res =
              RegOpenKeyEx(HKEY_LOCAL_MACHINE, path, 0, KEY_QUERY_VALUE, &hkey);
        }
        if (res == ERROR_SUCCESS) {
          DWORD type, size;
          wchar_t startup_binary[12];
          LONG result =
              RegQueryValueEx(hkey, it->Name(), nullptr, &type,
                              reinterpret_cast<BYTE*>(&startup_binary),
                              &(size = sizeof(startup_binary)));
          if (result == ERROR_SUCCESS) {
            if (type == REG_BINARY) {
              // any other binary other than this indicates that the program is
              // not set to launch at login
              wchar_t binary_accepted[12] = {0x00, 0x00, 0x00, 0x00,
                                             0x00, 0x00, 0x00, 0x00,
                                             0x00, 0x00, 0x00, 0x00};
              wchar_t binary_accepted_alt[12] = {0x02, 0x00, 0x00, 0x00,
                                                 0x00, 0x00, 0x00, 0x00,

Review comment (security):
Note: keys are case-insensitive. The old value of `SOFTWARE\Foo\Bar` here is inconsistent with the other code in the file that used `Software\Foo\Bar` instead, but it's functionally equivalent.

Code after:
  base::FilePath lookup_exe_path;
  if (options.path.empty()) {
    std::wstring process_exe_path;
    GetProcessExecPath(&process_exe_path);
    lookup_exe_path =
        base::CommandLine::FromString(process_exe_path).GetProgram();
  } else {
    lookup_exe_path =
        base::CommandLine::FromString(base::as_wcstr(options.path))
            .GetProgram();
  }

  if (!lookup_exe_path.empty()) {
    while (it->Valid()) {
      base::CommandLine registry_launch_cmd =
          base::CommandLine::FromString(it->Value());
      base::FilePath registry_launch_path = registry_launch_cmd.GetProgram();
      bool exe_match = base::FilePath::CompareEqualIgnoreCase(
          lookup_exe_path.value(), registry_launch_path.value());

      // add launch item to vector if it has a matching path (case-insensitive)
      if (exe_match) {
        LaunchItem launch_item;
        launch_item.name = it->Name();
        launch_item.path = registry_launch_path.value();
        launch_item.args = registry_launch_cmd.GetArgs();
        launch_item.scope = scope;
        launch_item.enabled = true;

        // attempt to update launch_item.enabled if there is a matching key
        // value entry in the StartupApproved registry
        const HKEY scope_key =
            scope == L"user" ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE;
        HKEY hkey;
        LONG res = RegOpenKeyEx(scope_key, StartupApprovedRun.c_str(), 0,
                                KEY_QUERY_VALUE, &hkey);
        if (res == ERROR_SUCCESS) {
          DWORD type, size;
          wchar_t startup_binary[12];
          LONG result =
              RegQueryValueEx(hkey, it->Name(), nullptr, &type,
                              reinterpret_cast<BYTE*>(&startup_binary),
                              &(size = sizeof(startup_binary)));
          if (result == ERROR_SUCCESS) {
            if (type == REG_BINARY) {
              // any other binary other than this indicates that the program is
              // not set to launch at login
              wchar_t binary_accepted[12] = {0x00, 0x00, 0x00, 0x00,
                                             0x00, 0x00, 0x00, 0x00,
                                             0x00, 0x00, 0x00, 0x00};
              wchar_t binary_accepted_alt[12] = {0x02, 0x00, 0x00, 0x00,