Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad data could cause crash #52

Open
aryaxt opened this issue Jun 1, 2016 · 0 comments
Open

Bad data could cause crash #52

aryaxt opened this issue Jun 1, 2016 · 0 comments
Assignees
Labels

Comments

@aryaxt
Copy link
Owner

aryaxt commented Jun 1, 2016

- (NSString *)propertyNameForObject:(NSObject *)object byCaseInsensitivePropertyName:(NSString *)caseInsensitivePropertyName
{
    NSString *result = nil;
    Class currentClass = [object class];
    NSString *key = [NSString stringWithFormat:@"%@.%@", NSStringFromClass(currentClass), caseInsensitivePropertyName];

    if (self.propertyNameDictionary[key])
        return self.propertyNameDictionary[key];

    while (currentClass && currentClass != [NSObject class])
    {
        unsigned int outCount, i;
        objc_property_t *properties = class_copyPropertyList(currentClass, &outCount);

        for (i = 0; i < outCount; i++)
        {
            objc_property_t property = properties[i];
            NSString *propertyName = [NSString stringWithUTF8String:property_getName(property)];

            if ([[propertyName lowercaseString] isEqual:[caseInsensitivePropertyName lowercaseString]])
            {
                result = propertyName;
                break;
            }
        }

        free(properties);

        if (result)
        {
            self.propertyNameDictionary[key] = result;
            return result;
        }

        currentClass = class_getSuperclass(currentClass);
    }

    return nil;
}

Do a null check on properties before calling free
Also do a null check for key?

@aryaxt aryaxt added the bug label Jun 1, 2016
@aryaxt aryaxt self-assigned this Jun 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant