From 328eefce733cd393dcae18f9043bff1444f16b7c Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 13 Jun 2022 12:37:22 +0200 Subject: [PATCH] [runtime] Fix 'skip_nested_brace' to not read past the string. Fixes #15253. Fix 'skip_nested_brace' to not double skip characters. Also add a test. Fixes https://github.com/xamarin/xamarin-macios/issues/15253. --- runtime/trampolines.m | 1 - tests/monotouch-test/ObjCRuntime/Messaging.cs | 13 ++++++++ .../ObjCRuntime/RegistrarTest.cs | 31 ++++++++++++++++++- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/runtime/trampolines.m b/runtime/trampolines.m index 4392c1d9d4aa..5a2473cbf718 100644 --- a/runtime/trampolines.m +++ b/runtime/trampolines.m @@ -425,7 +425,6 @@ case '}': return type++; default: - type++; break; } } diff --git a/tests/monotouch-test/ObjCRuntime/Messaging.cs b/tests/monotouch-test/ObjCRuntime/Messaging.cs index 756b54b1e426..76f601065571 100644 --- a/tests/monotouch-test/ObjCRuntime/Messaging.cs +++ b/tests/monotouch-test/ObjCRuntime/Messaging.cs @@ -260,5 +260,18 @@ public struct objc_super { [DllImport (LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")] public extern static void void_objc_msgSend_IntPtr_IntPtr_BlockLiteral (IntPtr receiver, IntPtr selector, IntPtr p1, IntPtr p2, ref BlockLiteral p3); + + [DllImport (LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")] + public extern static void void_objc_msgSend_NSRange_out_NSRange_ref_NSRange (IntPtr receiver, IntPtr selector, _LongNSRange p1, out _LongNSRange p2, ref _LongNSRange p3); + } + + public struct _LongNSRange { + public long Location; + public long Length; + public _LongNSRange (long location, long length) + { + Location = location; + Length = length; + } } } diff --git a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs index 1752cb22a8a1..b994bf5ce6a4 100644 --- a/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs +++ b/tests/monotouch-test/ObjCRuntime/RegistrarTest.cs @@ -74,6 +74,36 @@ public static Registrars CurrentRegistrar { } } + [Test] + public void NSRangeOutParameter () + { + using var obj = new NSRangeOutParameterClass (); + var a = new _LongNSRange (-1, -2); + var c = new _LongNSRange (-5, -6); + Messaging.void_objc_msgSend_NSRange_out_NSRange_ref_NSRange (obj.Handle, Selector.GetHandle ("passRange:getRange:refRange:"), a, out var b, ref c); + Assert.AreEqual (a.Location, (long) (-1), "post a Location"); + Assert.AreEqual (a.Length, (long) (-2), "post a Length"); + Assert.AreEqual (b.Location, (long) 3, "post b Location"); + Assert.AreEqual (b.Length, (long) 4, "post b Length"); + Assert.AreEqual (c.Location, (long) 5, "post c Location"); + Assert.AreEqual (c.Length, (long) 6, "post c Length"); + } + + class NSRangeOutParameterClass : NSObject { + [Export ("passRange:getRange:refRange:")] + public void DoIt (_LongNSRange a, out _LongNSRange b, ref _LongNSRange c) + { + Assert.AreEqual (a.Location, (long) (-1), "a Location"); + Assert.AreEqual (a.Length, (long) (-2), "a Length"); + Assert.AreEqual (c.Location, (long) (-5), "c Location"); + Assert.AreEqual (c.Length, (long) (-6), "c Length"); + + a = new _LongNSRange (1, 2); + b = new _LongNSRange (3, 4); + c = new _LongNSRange (5, 6); + } + } + [Test] public void RegistrarRemoval () { @@ -5423,7 +5453,6 @@ public static unsafe void Invoke (IntPtr block, nint value) } } #endif // !__WATCHOS__ && !__TVOS__ - } #if !__WATCHOS__