Skip to content

Commit

Permalink
Fix potential ArgumentOutOfRange exception during string length capping.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed May 10, 2022
1 parent b8cc84a commit d435e06
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/ObjCRuntime/Runtime.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,13 @@ static void log_coreclr_render (string message, params object[] argumentsToRende
arg = $"{inativeobj.Handle.ToString ()} ({obj.GetType ()})";
} else {
var toString = obj.ToString ();
// Print one line, and at most 256 characters.
var strLength = Math.Min (256, toString.Length);
var eol = toString.IndexOf ('\n');
if (eol != -1)
toString = toString.Substring (0, eol - 1) + " [...]";
if (toString.Length > 256)
toString = toString.Substring (0, 256) + " [...]";
if (eol != -1 && eol < strLength)
strLength = eol;
if (strLength != toString.Length)
toString = toString.Substring (0, strLength) + " [...]";

arg = $"{toString} ({obj.GetType ()})";
}
Expand Down

0 comments on commit d435e06

Please sign in to comment.