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

[PLAT-6632] Fix KSCrash state storage for apps with no CFBundleName #1103

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Bugsnag/KSCrash/Source/KSCrash/Recording/BSG_KSCrash.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@

@interface BSG_KSCrash ()

@property(nonatomic, readwrite, retain) NSString *bundleName;
@property(nonatomic, readwrite, retain) NSString *nextCrashID;

// Mirrored from BSG_KSCrashAdvanced.h to provide ivars
Expand All @@ -82,7 +81,6 @@ @implementation BSG_KSCrash
@synthesize userInfo = _userInfo;
@synthesize printTraceToStdout = _printTraceToStdout;
@synthesize onCrash = _onCrash;
@synthesize bundleName = _bundleName;
@synthesize logFilePath = _logFilePath;
@synthesize nextCrashID = _nextCrashID;
@synthesize introspectMemory = _introspectMemory;
Expand All @@ -105,7 +103,6 @@ + (BSG_KSCrash *)sharedInstance {

- (instancetype)init {
if ((self = [super init])) {
self.bundleName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"];
self.nextCrashID = [NSUUID UUID].UUIDString;
self.introspectMemory = YES;
self.maxStoredReports = 5;
Expand Down Expand Up @@ -162,11 +159,13 @@ - (void)setThreadTracingEnabled:(BOOL)threadTracingEnabled {
}

- (BSG_KSCrashType)install:(BSG_KSCrashType)crashTypes directory:(NSString *)directory {
bsg_kscrash_generate_report_initialize(directory.fileSystemRepresentation, self.bundleName.UTF8String);
bsg_kscrash_generate_report_initialize(directory.fileSystemRepresentation);
char *crashReportPath = bsg_kscrash_generate_report_path(self.nextCrashID.UTF8String, false);
char *recrashReportPath = bsg_kscrash_generate_report_path(self.nextCrashID.UTF8String, true);
NSString *stateFilePrefix = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"]
/* Not all processes have an Info.plist */ ?: NSProcessInfo.processInfo.processName;
NSString *stateFilePath = [directory stringByAppendingPathComponent:
[self.bundleName stringByAppendingString:@BSG_kCrashStateFilenameSuffix]];
[stateFilePrefix stringByAppendingString:@BSG_kCrashStateFilenameSuffix]];

bsg_kscrash_setHandlingCrashTypes(crashTypes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
extern "C" {
#endif

void bsg_kscrash_generate_report_initialize(const char *directory, const char *bundleName);
void bsg_kscrash_generate_report_initialize(const char *directory);

/**
* Generates a new UUID. Not async signal safe. Caller responsible for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
#include <string.h>

static char *report_directory;
static char *bundle_name;

void bsg_kscrash_generate_report_initialize(const char *directory, const char *bundleName) {
void bsg_kscrash_generate_report_initialize(const char *directory) {
report_directory = directory ? strdup(directory) : NULL;
bundle_name = bundleName ? strdup(bundleName) : NULL;
}

char *bsg_kscrash_generate_report_identifier(void) {
Expand All @@ -25,6 +23,6 @@ void bsg_kscrash_generate_report_initialize(const char *directory, const char *b
}
char *type = is_recrash_report ? "RecrashReport" : "CrashReport";
char *path = NULL;
asprintf(&path, "%s/%s-%s-%s.json", report_directory, bundle_name, type, identifier);
asprintf(&path, "%s/%s-%s.json", report_directory, type, identifier);
return path;
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changelog
[#1097](https://github.com/bugsnag/bugsnag-cocoa/issues/1097)
[#1101](https://github.com/bugsnag/bugsnag-cocoa/pull/1101)

* Fix KSCrash state storage for apps with no CFBundleName.
[#1103](https://github.com/bugsnag/bugsnag-cocoa/pull/1103)

## 6.9.3 (2021-05-26)

### Bug fixes
Expand Down