[Mono-bugs] [Bug 80141][Maj] New - Linux: Incorrect RegistryKey.SetValue() Serialization

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Mon Dec 4 01:48:40 EST 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by kevin.fitzgerald at soarce.us.

http://bugzilla.ximian.com/show_bug.cgi?id=80141

--- shadow/80141	2006-12-04 01:48:40.000000000 -0500
+++ shadow/80141.tmp.13508	2006-12-04 01:48:40.000000000 -0500
@@ -0,0 +1,156 @@
+Bug#: 80141
+Product: Mono: Class Libraries
+Version: 1.0
+OS: GNU/Linux [Other]
+OS Details: Ubuntu 6.10 Edgy
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: kevin.fitzgerald at soarce.us               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Linux: Incorrect RegistryKey.SetValue() Serialization
+
+Description of Problem:
+
+Microsoft.Win32.RegistryKey.SetValue() incorrectly writes .XML registry
+values in a Linux environment. More importantly, "&" (Ampersands) are not
+escaped as "&". This problem does not occur in a Microsoft Windows
+environment.
+
+Steps to reproduce the problem:
+
+1. Create an application that accesses a registry key, and stores a value
+on a Linux environment.
+
+This is a working example I created to model the problem I'm having with my
+actual code:
+
+/**********************************************************/
+using System;
+using Microsoft.Win32;
+
+namespace RegTest
+{
+   class MainClass
+   {
+      public static void Main(string[] args)
+      {
+            // On the second execution of this program,
+            // this line will cause a WARNING. (See below for stack trace)
+            RegistryKey regkey =
+Registry.LocalMachine.CreateSubKey("SOFTWARE\\regtest");
+
+            // This shows what the current value is
+            Console.WriteLine("Current Value: " + regkey.GetValue("URL"));
+						
+            // Enter a value containing at least one "&"
+            Console.WriteLine("Enter new URL:" );
+            regkey.SetValue( "URL", Console.ReadLine() );
+						
+            // This shows that once set, the value is OK.
+            Console.WriteLine("Key Value: " + regkey.GetValue("URL"));
+      }
+   }
+}
+/**********************************************************/
+
+2. Run this application. Since the key did not exist this time, nothing
+should be displayed in the "Current Value: " line. Next, enter a value,
+such as "http://google.com/?arg=val&arg2=val2". The value is displayed back
+on the screen using the RegistryKey object and the application terminates.
+
+3. Run the application again. An error will be displayed on the screen when
+accessing the key.
+
+
+Actual Results:
+
+This is direct copy-and-paste from the terminal window using the above
+application and steps listed above.
+
+# FIRST RUN
+----------------------------------------------------------------------
+ubuntu at ubuntu:~/Projects/RegTest/RegTest/bin/Release$ ./RegTest.exe 
+Current Value: 
+Enter new URL:
+http://google.com/?arg=val&arg2=val2
+Key Value: http://google.com/?arg=val&arg2=val2
+----------------------------------------------------------------------
+
+# SECOND RUN
+----------------------------------------------------------------------
+ubuntu at ubuntu:~/Projects/RegTest/RegTest/bin/Release$ ./RegTest.exe 
+While loading registry key at
+/home/ubuntu/.mono/registry/LocalMachine/software/regtest/values.xml:
+System.Security.XmlSyntaxException: Invalid XML. --->
+Mono.Xml.SmallXmlParserException: Expected ';' but got =. At (3,57)
+  at Mono.Xml.SmallXmlParser.Expect (Int32 c) [0x00000] 
+  at Mono.Xml.SmallXmlParser.ReadReference () [0x00000] 
+  at Mono.Xml.SmallXmlParser.ReadCharacters () [0x00000] 
+  at Mono.Xml.SmallXmlParser.ReadContent () [0x00000] 
+  at Mono.Xml.SmallXmlParser.Parse (System.IO.TextReader input,
+IContentHandler handler) [0x00000] 
+  at Mono.Xml.SecurityParser.LoadXml (System.String xml) [0x00000] 
+  at System.Security.SecurityElement.FromString (System.String xml)
+[0x00000] --- End of inner exception stack trace ---
+
+  at System.Security.SecurityElement.FromString (System.String xml) [0x00000] 
+  at Microsoft.Win32.KeyHandler.Load () [0x00000] 
+Current Value: 
+Enter new URL:
+...
+----------------------------------------------------------------------
+
+Expected Results:
+
+On the second run of the application, the error listed above should not
+occur and the "Current Value: " line should contain the URL stored in the
+values.xml file: "http://google.com/?arg=val&arg2=val2"
+
+How often does this happen? 
+
+This occurs 100% of the time when a value is stored in the registry on a
+Linux system that contains an "&" (Ampersand).
+
+Suspected Cause:
+
+If I were to guess, I'd say that the SetValue() algorithm is incorrectly
+writing values to their respective values.xml file in the ~/.mono/registry/
+directory. 
+
+Additional Information:
+
+Here is the contents of the values.xml file after the first run of the
+application:
+
+----------------------------------------------------------------------
+ubuntu at ubuntu:~/.mono/registry/LocalMachine/software/regtest$ cat values.xml
+<values>
+   <value name="URL"
+          type="string">http://google.com/?arg=val&arg2=val2</value>
+</values>
+----------------------------------------------------------------------
+
+Just by viewing this file shows that the value is not being correctly
+escaped. The correct value should be "http://google.com/?arg=val&amp;arg2=val2"
+
+After making this change to the file and running the application again
+reveals this:
+----------------------------------------------------------------------
+ubuntu at ubuntu:~/Projects/RegTest/RegTest/bin/Release$ ./RegTest.exe 
+Current Value: http://google.com/?arg=val&arg2=val2
+Enter new URL:
+...
+----------------------------------------------------------------------
+
+This is the expected result we should get.
+
+I marked this bug as MAJOR because the probability of "&" (Ampersands)
+showing up in cross-platform applications is likely, and loss of settings
+and data can occur. This is a very undesirable.


More information about the mono-bugs mailing list