From 6a57b7578c04482a2a3586654e20ba588dc320f2 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 2 Sep 2022 18:57:41 +0200 Subject: [PATCH] [Runtime] Fix comparing a pointer to a UTF8 string with a managed string with embedded nulls. A managed string can contain embedded nulls, while a native UTF8 string won't, which means that we can't depend on finding a different character between the two strings to determine whether we've reached the end of the native UTF8 string or not. --- src/ObjCRuntime/Runtime.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ObjCRuntime/Runtime.cs b/src/ObjCRuntime/Runtime.cs index 7fd1d573a5e7..bd8ab8f90795 100644 --- a/src/ObjCRuntime/Runtime.cs +++ b/src/ObjCRuntime/Runtime.cs @@ -1946,6 +1946,8 @@ internal static bool StringEquals (IntPtr utf8, string? str) } if (b != (short) str [i]) return false; + if (b == 0) + return false; } return c [str.Length] == 0; }