From: Jay Freeman (saurik) <saurik@saurik.com>
Date: Wed, 14 Oct 2009 22:19:19 +0000 (+0000)
Subject: Fixed a stupid set of bugs that broke HelloCycript: first a NULL dereference in sig... 
X-Git-Tag: v0.9.432~350
X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/3a1b79a7408f23b6c54565ac8410dee4c0546c2c

Fixed a stupid set of bugs that broke HelloCycript: first a NULL dereference in sig::Parse, and second trying to cast objc_registerClassPair to a Class rather than its argument.
---

diff --git a/Library.mm b/Library.mm
index 9cb0060..252f9a4 100644
--- a/Library.mm
+++ b/Library.mm
@@ -2016,8 +2016,10 @@ MSHook(void, objc_registerClassPair, Class _class) {
 
 static JSValueRef objc_registerClassPair_(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
     CYTry {
+        if (count != 1)
+            @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"incorrect number of arguments to objc_registerClassPair" userInfo:nil];
         CYPool pool;
-        Class _class(CYCastNSObject(pool, context, object));
+        Class _class(CYCastNSObject(pool, context, arguments[0]));
         $objc_registerClassPair(_class);
         return CYJSUndefined(context);
     } CYCatch
diff --git a/sig/parse.cpp b/sig/parse.cpp
index 18f0668..2f007de 100644
--- a/sig/parse.cpp
+++ b/sig/parse.cpp
@@ -164,8 +164,9 @@ struct Type *Parse_(apr_pool_t *pool, const char **name, char eos, bool named, C
                 type->data.data.type = NULL;
             } else {
                 type->data.data.type = Parse_(pool, name, eos, named, callback);
-                if (type->data.data.type->primitive == void_P)
-                    type->data.data.type = NULL;
+                sig::Type *&target(type->data.data.type);
+                if (target != NULL && target->primitive == void_P)
+                    target = NULL;
             }
         break;