Bug 25106

Summary: Microsoft.Win32.Registry.GetValue() requires write permission on Windows
Product: [Mono] Class Libraries Reporter: Mirco Bauer <meebey>
Component: mscorlibAssignee: Bugzilla <bugzilla>
Severity: normal CC: mono-bugs+mono
Priority: ---    
Version: unspecified   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Repro of the bug
Tested fix

Description Mirco Bauer 2014-12-05 10:38:59 UTC
Using Microsoft.Win32.Registry.GetValue() on Windows will lead to a SecurityException if the user does not have admin rights.

Unhandled Exception:
System.Security.SecurityException: A security error has been detected.
  at Microsoft.Win32.Win32RegistryApi.GenerateException (Int32 errorCode) [0x00000] in <filename unknown>:0
  at Microsoft.Win32.Win32RegistryApi.OpenSubKey (Microsoft.Win32.RegistryKey rkey, System.String keyName, Boolean writable) [0x00000] in <filename unknown>:0
  at Microsoft.Win32.RegistryKey.OpenSubKey (System.String name, Boolean writable) [0x00000] in <filename unknown>:0
  at (wrapper remoting-invoke-with-check) Microsoft.Win32.RegistryKey:OpenSubKey (string,bool)
  at Microsoft.Win32.Registry.ToKey (System.String keyName, Boolean setting) [0x00000] in <filename unknown>:0
  at Microsoft.Win32.Registry.GetValue (System.String keyName, System.String valueName, System.Object defaultValue) [0x00000] in <filename unknown>:0
  at Smuxi.Frontend.Gnome.Frontend.InitGtkPathWin () [0x00000] in <filename unknown>:0
  at Smuxi.Frontend.Gnome.Frontend.InitGtk (System.String[] args) [0x00000] in <filename unknown>:0
  at Smuxi.Frontend.Gnome.Frontend.Init (System.String[] args) [0x00000] in <filename unknown>:0
  at Smuxi.Frontend.Gnome.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0

I could track the issue down to the code in Registry.cs:

The 2nd parameter of OpenSubKey() asks for write permission. It should simply pass the "setting" variable instead.

I will create a PR with a tested fix.
Comment 1 Mirco Bauer 2014-12-05 10:40:05 UTC
Created attachment 8975 [details]
Repro of the bug
Comment 2 Mirco Bauer 2014-12-05 10:40:37 UTC
Created attachment 8976 [details]
Tested fix
Comment 3 Mirco Bauer 2014-12-05 10:43:10 UTC
The original report was in Smuxi, which can be found here:
Comment 4 Mirco Bauer 2014-12-08 04:42:42 UTC
Pull request: https://github.com/mono/mono/pull/1445