Просмотр исходного кода

2009-10-08 Sebastien Pouliot <[email protected]>

	* StackFrame.cs: Introduce a new GetSecureFileName method that
	will deal with CAS (regular framework) and will remove the path
	(for Moonlight) on a stack frame.
	* StackTrace.cs: Use the new StackFrame.GetSecureFileName to
	simplify logic


svn path=/trunk/mcs/; revision=143802
Sebastien Pouliot 16 лет назад
Родитель
Сommit
ce772c30bf

+ 8 - 0
mcs/class/corlib/System.Diagnostics/ChangeLog

@@ -1,3 +1,11 @@
+2009-10-08  Sebastien Pouliot  <[email protected]>
+
+	* StackFrame.cs: Introduce a new GetSecureFileName method that
+	will deal with CAS (regular framework) and will remove the path
+	(for Moonlight) on a stack frame.
+	* StackTrace.cs: Use the new StackFrame.GetSecureFileName to
+	simplify logic
+
 2009-09-18  Sebastien Pouliot  <[email protected]>
 
 	* StackFrame.cs: Avoid imperative CAS checks for NET_2_1

+ 27 - 12
mcs/class/corlib/System.Diagnostics/StackFrame.cs

@@ -139,6 +139,32 @@ namespace System.Diagnostics {
 #endif
                         return fileName;
                 }
+
+		internal string GetSecureFileName ()
+		{
+			string filename = "<filename unknown>";
+			if (fileName == null)
+				return filename;
+#if !NET_2_1 || MONOTOUCH
+			try {
+				filename = GetFileName ();
+			}
+			catch (SecurityException) {
+				// CAS check failure
+			}
+#else
+			// Silverlight always return <filename unknown> but that's not very useful for debugging
+			// OTOH we do not want to share any details about the original file system (even if they
+			// are likely available in the debugging symbols files)
+			try {
+				filename = Path.GetFileName (fileName);
+			}
+			catch (ArgumentException) {
+				// e.g. invalid chars in filename
+			}
+#endif
+			return filename;
+		}
                 
                 public virtual int GetILOffset()
                 {
@@ -183,18 +209,7 @@ namespace System.Diagnostics {
 			}
 
 			sb.Append (Locale.GetText (" in file:line:column "));
-
-			if (fileName == null) {
-				sb.Append (Locale.GetText ("<filename unknown>"));
-			} else {
-				try {
-					sb.Append (GetFileName ());
-				}
-				catch (SecurityException) {
-					sb.Append (Locale.GetText ("<filename unknown>"));
-				}
-			}
-
+			sb.Append (GetSecureFileName ());
 			sb.AppendFormat (":{0}:{1}", lineNumber, columnNumber);
 			return sb.ToString ();
 		}

+ 4 - 11
mcs/class/corlib/System.Diagnostics/StackTrace.cs

@@ -232,17 +232,10 @@ namespace System.Diagnostics {
 
 				if (debug_info) {
 					// we were asked for debugging informations
-					try {
-						// but that doesn't mean we have the debug information available
-						string fname = frame.GetFileName ();
-						if ((fname != null) && (fname.Length > 0))
-							sb.AppendFormat (debuginfo, fname, frame.GetFileLineNumber ());
-					}
-					catch (SecurityException) {
-						// don't leak information (about the filename) if the security 
-						// manager doesn't allow it (but don't loop on this exception)
-						debug_info = false;
-					}
+					// but that doesn't mean we have the debug information available
+					string fname = frame.GetSecureFileName ();
+					if (fname != "<filename unknown>")
+						sb.AppendFormat (debuginfo, fname, frame.GetFileLineNumber ());
 				}
 			}
 			return sb.ToString ();