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)

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


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

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