Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Ungureanu <teromario@yahoo.com>2017-09-26 23:34:07 +0300
committerAlexander Köplinger <alex.koeplinger@outlook.com>2017-09-26 23:34:07 +0300
commit98e4187cf080c2004c1c1c268e1b43faf1b4613f (patch)
tree2e742a304ef1672d0cac1ad212c5084c9cfa76b5 /mcs/class/Mono.Posix
parentb586119cb961894e53e361ca91cb23f1ff2eb791 (diff)
[Mono.Unix] Fix crasher in StringToHeap (#5639)
In case StringToHeap (string, Encoding) was called with a null string, it would unconditionally reference the string when trying to query the string's length. Bug 10074 - Error while updating status of command: MonoDevelop.Ide.Commands.ViewCommands.LayoutList
Diffstat (limited to 'mcs/class/Mono.Posix')
-rw-r--r--mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs3
-rw-r--r--mcs/class/Mono.Posix/Test/Mono.Unix/UnixMarshalTest.cs7
2 files changed, 10 insertions, 0 deletions
diff --git a/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs b/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs
index 0b01eb19ad4..7d39fd4c43f 100644
--- a/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs
+++ b/mcs/class/Mono.Posix/Mono.Unix/UnixMarshal.cs
@@ -309,6 +309,9 @@ namespace Mono.Unix {
public static IntPtr StringToHeap (string s, Encoding encoding)
{
+ if (s == null)
+ return IntPtr.Zero;
+
return StringToHeap (s, 0, s.Length, encoding);
}
diff --git a/mcs/class/Mono.Posix/Test/Mono.Unix/UnixMarshalTest.cs b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixMarshalTest.cs
index 8ae50b98c97..9b0ce35d961 100644
--- a/mcs/class/Mono.Posix/Test/Mono.Unix/UnixMarshalTest.cs
+++ b/mcs/class/Mono.Posix/Test/Mono.Unix/UnixMarshalTest.cs
@@ -41,6 +41,13 @@ namespace MonoTests.Mono.Unix {
#endif
[Test]
+ public void BXC10074 ()
+ {
+ var result = UnixMarshal.StringToHeap (null, Encoding.ASCII);
+ Assert.AreEqual (IntPtr.Zero, result, "This used to crash due to a NullReferenceException");
+ }
+
+ [Test]
public void TestStringToHeap ()
{
object[] data = {