Bug 25106 - Microsoft.Win32.Registry.GetValue() requires write permission on Windows
Summary: Microsoft.Win32.Registry.GetValue() requires write permission on Windows
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-05 10:38 UTC by Mirco Bauer
Modified: 2014-12-08 05:15 UTC (History)
1 user (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Repro of the bug (537 bytes, text/x-csharp)
2014-12-05 10:40 UTC, Mirco Bauer
Details
Tested fix (2.29 KB, text/x-csharp)
2014-12-05 10:40 UTC, Mirco Bauer
Details

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:
https://github.com/mono/mono/blob/master/mcs/class/corlib/Microsoft.Win32/Registry.cs#L96

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:
https://smuxi.im/issues/show/1004
Comment 4 Mirco Bauer 2014-12-08 04:42:42 UTC
Pull request: https://github.com/mono/mono/pull/1445

Note You need to log in before you can comment on or make changes to this bug.