Skip to content

Commit afc647c

Browse files
authored
redact UDID information from binary image data (#6382)
redact UDID information from binary image data
1 parent fa7b3f9 commit afc647c

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Unreleased
22
- [added] Added stackFrameWithAddress API for recording custom errors that are symbolicated on the backend (#5975).
33
- [fixed] Fixed comment typos (#6363).
4+
- [fixed] Remove device information from binary image data crash info entries (#6382).
45

56
# v4.5.0
67
- [fixed] Fixed a compiler warning and removed unused networking code (#6210).

Crashlytics/Crashlytics/Components/FIRCLSProcess.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,12 @@ static void FIRCLSProcessRecordCrashInfo(FIRCLSFile *file) {
800800
continue;
801801
}
802802

803+
// The crash_info_t's message may contain the device's UDID, in this case,
804+
// make sure that we do our best to redact that information before writing the
805+
// rest of the message to disk. This also has the effect of not uploading that
806+
// information in the subsequent crash report.
807+
FIRCLSRedactUUID(string);
808+
803809
FIRCLSFileWriteArrayEntryHexEncodedString(file, string);
804810
}
805811
}

Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bool FIRCLSReadString(vm_address_t src, char** dest, size_t maxlen);
3535
const char* FIRCLSDupString(const char* string);
3636

3737
bool FIRCLSUnlinkIfExists(const char* path);
38+
void FIRCLSRedactUUID(char* value);
3839

3940
#if __OBJC__
4041
void FIRCLSDispatchAfter(float timeInSeconds, dispatch_queue_t queue, dispatch_block_t block);

Crashlytics/Crashlytics/Helpers/FIRCLSUtility.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,37 @@ bool FIRCLSUnlinkIfExists(const char* path) {
156156
return FIRCLSNormalizeUUID(FIRCLSGenerateUUID());
157157
}
158158

159+
// Redacts a UUID wrapped in parenthesis from a char* using strchr, which is async safe.
160+
// Ex.
161+
// "foo (bar) (45D62CC2-CFB5-4E33-AB61-B0684627F1B6) baz"
162+
// becomes
163+
// "foo (bar) (********-****-****-****-************) baz"
164+
void FIRCLSRedactUUID(char* value) {
165+
if (value == NULL) {
166+
return;
167+
}
168+
char* openParen = value;
169+
// find the index of the first paren
170+
while ((openParen = strchr(openParen, '(')) != NULL) {
171+
// find index of the matching close paren
172+
const char* closeParen = strchr(openParen, ')');
173+
if (closeParen == NULL) {
174+
break;
175+
}
176+
// if the distance between them is 37, traverse the characters
177+
// and replace anything that is not a '-' with '*'
178+
if (closeParen - openParen == 37) {
179+
for (int i = 1; i < 37; ++i) {
180+
if (*(openParen + i) != '-') {
181+
*(openParen + i) = '*';
182+
}
183+
}
184+
break;
185+
}
186+
openParen++;
187+
}
188+
}
189+
159190
NSString* FIRCLSNSDataToNSString(NSData* data) {
160191
NSString* string;
161192
char* buffer;

Crashlytics/UnitTests/FIRCLSUtilityTests.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,56 @@ - (void)testHexToStringWithNonPrintableCharacters {
7777
XCTAssertEqualObjects([NSString stringWithUTF8String:string], @"52d04e1f", @"");
7878
}
7979

80+
- (void)testRedactUUIDWithExpectedPattern {
81+
const char* readonly = "CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
82+
"(45D62CC2-CFB5-4E33-AB61-B0684627F1B6) - Runtime: iOS 13.4 (17E8260) - "
83+
"DeviceType: iPhone SE (2nd generation)";
84+
size_t len = strlen(readonly);
85+
char message[len];
86+
strcpy(message, readonly);
87+
88+
FIRCLSRedactUUID(message);
89+
90+
NSString* actual = [NSString stringWithUTF8String:message];
91+
NSString* expected = @"CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
92+
@"(********-****-****-****-************) - Runtime: iOS 13.4 (17E8260) - "
93+
@"DeviceType: iPhone SE (2nd generation)";
94+
95+
XCTAssertEqualObjects(actual, expected);
96+
}
97+
98+
- (void)testRedactUUIDWithMalformedPattern {
99+
const char* readonly = "CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
100+
"(45D62CC2-CFB5-4E33-AB61-B0684627F1B6";
101+
size_t len = strlen(readonly);
102+
char message[len];
103+
strcpy(message, readonly);
104+
105+
FIRCLSRedactUUID(message);
106+
107+
NSString* actual = [NSString stringWithUTF8String:message];
108+
NSString* expected = @"CoreSimulator 704.12.1 - Device: iPhone SE (2nd generation) "
109+
@"(45D62CC2-CFB5-4E33-AB61-B0684627F1B6";
110+
111+
XCTAssertEqualObjects(actual, expected);
112+
}
113+
114+
- (void)testRedactUUIDWithoutUUID {
115+
const char* readonly = "Fatal error: file /Users/test/src/foo/bar/ViewController.swift, line 25";
116+
size_t len = strlen(readonly);
117+
char message[len];
118+
strcpy(message, readonly);
119+
120+
FIRCLSRedactUUID(message);
121+
122+
NSString* actual = [NSString stringWithUTF8String:message];
123+
NSString* expected = @"Fatal error: file /Users/test/src/foo/bar/ViewController.swift, line 25";
124+
125+
XCTAssertEqualObjects(actual, expected);
126+
}
127+
128+
- (void)testRedactUUIDWithNull {
129+
char* message = NULL;
130+
XCTAssertNoThrow(FIRCLSRedactUUID(message));
131+
}
80132
@end

0 commit comments

Comments
 (0)