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

Attempted to dereference null pointer in +[BSG_KSJSONCodec decode:options:error:] #637

Closed
Naugladur opened this issue May 27, 2020 · 2 comments
Labels
bug Confirmed bug released This feature/bug fix has been released

Comments

@Naugladur
Copy link

Description

I get a lot of crashes with EXC_BAD_ACCESS: Attempted to dereference null pointer

Environment

Library versions:

  • Bugsnag version (from your Podfile, Podfile.lock, or elsewhere): 5.23.2
  • CocoaPods version (if any) (pod -v): -
  • Carthage version (if any): -
  • iOS/tvOS/macOS version(s): all
  • debug mode or production?: both
  • How are you initializing Bugsnag? Can you share a snippet of your
    AppDelegate where Bugsnag is configured?

Integrated via subproject in workspace.

func setup() {
    let config = BugsnagConfiguration()
    config.apiKey = "Key"
    config.releaseStage = "production"
    Bugsnag.start(with: config)
}

Code snippet

I think the problem is in BSG_KSCrashReportStore.m in 88 line:

- (NSDictionary *)fileWithId:(NSString *)fileId {
    NSDictionary *dict = [super fileWithId:fileId];

    if (dict != nil) {
        return dict;
    } else {
        NSMutableDictionary *fileContents = [NSMutableDictionary new];
        NSMutableDictionary *recrashReport =
                [self readFile:[self pathToRecrashReportWithID:fileId] error:nil]; // <-- here
        BSGDictInsertIfNotNil(fileContents, recrashReport, @BSG_KSCrashField_RecrashReport);
        return fileContents;
    }
}

Passing nil to method

- (NSMutableDictionary *)readFile:(NSString *)path
                            error:(NSError *__autoreleasing *)error {
...
            [BSG_KSJSONCodec decode:jsonData
                            options:BSG_KSJSONDecodeOptionIgnoreNullInArray |
                                    BSG_KSJSONDecodeOptionIgnoreNullInObject |
                                    BSG_KSJSONDecodeOptionKeepPartialObject
                              error:error];
...
}

And call -[BSG_KSJSONCodec decode:options:error:] with nil in third param as result:

+ (id)decode:(NSData *)JSONData
         options:(BSG_KSJSONDecodeOption)decodeOptions
             error:(NSError *__autoreleasing *)error {
    *error = nil; // <-- EXC_BAD_ACCESS: Attempted to dereference null pointer.
    id result = nil;
    @try {
        result = [NSJSONSerialization JSONObjectWithData:JSONData options:0 error:error];
    } @catch (NSException *exception) {
        result = @{};
    }
    return result;
}
Crash report:
EXC_BAD_ACCESS: Attempted to dereference null pointer.

0  myApp                   +[BSG_KSJSONCodec decode:options:error:] (BSG_KSJSONCodecObjC.m:507:12)
1  myApp                   -[BugsnagFileStore readFile:error:] (BugsnagFileStore.m:309:13)
2  myApp                   -[BSG_KSCrashReportStore readFile:error:] (BSG_KSCrashReportStore.m:165:35)
3  myApp                   -[BSG_KSCrashReportStore fileWithId:] (BSG_KSCrashReportStore.m:88:17)
4  myApp                   -[BugsnagFileStore allFilesByName] (BugsnagFileStore.m:139:38)
5  myApp                   -[BSG_KSCrash allReportsByFilename] (BSG_KSCrash.m:378:12)
6  myApp                   -[BSG_KSCrash sendAllReportsWithCompletion:] (BSG_KSCrash.m:260:29)
7  myApp                   -[BSGDeliveryOperation main] (BugsnagErrorReportApiClient.m:32:13)
8  Foundation              ___NSOPERATION_IS_INVOKING_MAIN__
9  Foundation              -[NSOperation start]
10 Foundation              ___NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__
11 Foundation              ___NSOQSchedule_f
12 libdispatch.dylib       __dispatch_call_block_and_release
13 libdispatch.dylib       __dispatch_client_callout
14 libdispatch.dylib       __dispatch_continuation_pop
15 libdispatch.dylib       __dispatch_async_redirect_invoke
16 libdispatch.dylib       __dispatch_root_queue_drain
17 libdispatch.dylib       __dispatch_worker_thread2
18 libsystem_pthread.dylib __pthread_wqthread
@mattdyoung
Copy link

Hi @Naugladur

Thanks for the report and for the related PR.

We're just reviewing now. Would you be able to email [email protected] and confirm which account / project you're seeing these errors on in case that helps add context for our investigation and testing of the fix.

@mattdyoung mattdyoung added the bug Confirmed bug label May 27, 2020
@bugsnagbot bugsnagbot added the scheduled Work is starting on this feature/bug label Jun 2, 2020
@mattdyoung
Copy link

Fixed in v6.0.0.

Note: There are a number of breaking changes in v6.0.0 as part of an effort to improve the interface and make it more consistent across our error reporting libraries, so please refer to the upgrade guide:
https:/bugsnag/bugsnag-cocoa/blob/master/UPGRADING.md

@mattdyoung mattdyoung added released This feature/bug fix has been released and removed scheduled Work is starting on this feature/bug labels Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug released This feature/bug fix has been released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants