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

Fix in FLEXPointerIsValidObjcObject

Fix one of many potential crashes. Added notes describing more potential crashes to fix in the future.
Tanner Bennett лет назад: 6
Родитель
Сommit
05bd084174

+ 14 - 3
Classes/Utility/Runtime/FLEXObjcInternal.mm

@@ -180,12 +180,23 @@ BOOL FLEXPointerIsValidObjcObject(const void *ptr)
     // We check if the returned class is readable because object_getClass
     // can return a garbage value when given a non-nil pointer to a non-object
     Class cls = object_getClass((__bridge id)ptr);
-    if (cls && FLEXPointerIsReadable((__bridge void *)cls) && object_isClass(cls)) {
-        return YES;
+    if (cls && FLEXPointerIsReadable((__bridge void *)cls)) {
+        // Just because this pointer is readable doesn't mean whatever is at
+        // it's ISA offset is readable. We need to do the same checks on it's ISA.
+        // Even this isn't perfect, because once we call object_isClass, we're
+        // going to dereference a member of the metaclass, which may or may not
+        // be readable itself. For the time being there is no way to access it
+        // to check here, and I have yet to hard-code a solution.
+        Class metaclass = object_getClass(cls);
+        if (metaclass && FLEXPointerIsReadable((__bridge void *)metaclass)) {
+            if (object_isClass(cls)) {
+                return YES;
+            }
+        }
     }
 
     return NO;
 }
 
     
-}
+} // End extern "C"

+ 1 - 1
Classes/Utility/Runtime/FLEXRuntimeUtility.m

@@ -657,7 +657,7 @@ const unsigned int kFLEXNumberOfImplicitArgs = 2;
 
 + (NSString *)readableTypeForEncoding:(NSString *)encodingString
 {
-    if (!encodingString) {
+    if (!encodingString.length) {
         return @"???";
     }