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

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Dec 7 05:43:30 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 03:17:17.000000000 -0500
+++ shadow/80141.tmp.19264	2006-12-07 05:43:30.000000000 -0500
@@ -3,13 +3,13 @@
 Version: 1.0
 OS: GNU/Linux [Other]
 OS Details: Ubuntu 6.10 Edgy
 Status: NEW   
 Resolution: 
 Severity: Unknown
-Priority: Major
+Priority: Blocker
 Component: CORLIB
 AssignedTo: mono-bugs at ximian.com                            
 ReportedBy: kevin.fitzgerald at soarce.us               
 QAContact: mono-bugs at ximian.com
 TargetMilestone: ---
 URL: 
@@ -162,6 +162,89 @@
 
 I'm going to start digging into the current most svn code to see what
 I can dig up...
 
 I haven't tested anything yet, but it might be as simple as a one line
 fix to UnixRegistryApi.cs.
+
+------- Additional Comments From kevin.fitzgerald at soarce.us  2006-12-07 05:43 -------
+I tracked down what was causing this error, and it turns out that it
+DOES just boil down to lack of escaping a string.
+
+In more technical terms:
+
+When a SecurityElement is used for creating an xml structure for the
+values.xml file, according to the Microsoft spec, the
+SecurityElement.Text and Security.AddAttribute(key,val) values need to
+be escaped PRIOR to being assigned to the object. This was not being
+preformed in the file UnixRegistryApi.cs.
+
+I have made the appropriate changes. The only section needing
+modification is the KeyHandler.Save() method. I have attached my
+proposed patch and full plain-text file. A test case can be seen above
+in the initial report. This patch solves the test case.
+
+In summary:
+====================================================================void
+// With SecurityElement.Text = value, and
+SecurityElement.AddAttribute(key, value)
+// the values must be escaped prior to being assigned. 
+Save ()
+{
+	if (IsMarkedForDeletion)
+		return;
+
+	if (!File.Exists (file) && values.Count == 0)
+		return;
+
+	SecurityElement se = new SecurityElement ("values");
+	
+	// With SecurityElement.Text = value, and
+SecurityElement.AddAttribute(key, value)
+	// the values must be escaped prior to being assigned. 
+	foreach (DictionaryEntry de in values){
+		object val = de.Value;
+		SecurityElement value = new SecurityElement ("value");
+		value.AddAttribute ("name", SecurityElement.Escape ((string) de.Key));
+		
+		if (val is string){
+			value.AddAttribute ("type", "string");
+			value.Text = SecurityElement.Escape ((string) val);
+		} else if (val is int){
+			value.AddAttribute ("type", "int");
+			value.Text = val.ToString ();
+		} else if (val is long) {
+			value.AddAttribute ("type", "qword");
+			value.Text = val.ToString ();
+		} else if (val is byte []){
+			value.AddAttribute ("type", "bytearray");
+			value.Text = Convert.ToBase64String ((byte[]) val);
+		} else if (val is ExpandString){
+			value.AddAttribute ("type", "expand");
+			value.Text = SecurityElement.Escape (val.ToString ());
+		} else if (val is string []){
+			value.AddAttribute ("type", "string-array");
+
+			foreach (string ss in (string[]) val){
+				SecurityElement str = new SecurityElement ("string");
+				str.Text = SecurityElement.Escape (ss); 
+				value.AddChild (str);
+			}
+		}
+		se.AddChild (value);
+	}
+
+	using (FileStream fs = File.Create (file)){
+		StreamWriter sw = new StreamWriter (fs);
+
+		sw.Write (se.ToString ());
+		sw.Flush ();
+	}
+}
+====================================================================
+
+I am also escalating this bug to Blocker because it *will* cause data
+loss or a crash if '<', '>', '&', '"', or "'" show up in a key
+value/attribute, which is a major portability issue.
+
+Could somebody check this into SVN for me?
+Thanks!


More information about the mono-bugs mailing list