Skip to content

Commit 30e1ff3

Browse files
authored
Fix checking the result of malloc (#4878)
* Fix checking the result of malloc Also make FIRCoreDiagnostics project generable again * Fix compilation error * Update CHANGELOGs
1 parent 4aa3b78 commit 30e1ff3

File tree

6 files changed

+21
-5
lines changed

6 files changed

+21
-5
lines changed

Firebase/CoreDiagnostics/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# v1.2.1
22
- Fixed a bug that would manifest if a proto ended up being > 16,320 bytes.
3+
- Now checks the result of malloc. (#4872)
34

45
# v1.2.0
56
- Added basic watchOS support.

Firebase/CoreDiagnostics/FIRCDLibrary/FIRCoreDiagnostics.m

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,10 @@ + (NSString *)deviceModel {
237237
*/
238238
pb_bytes_array_t *FIREncodeData(NSData *data) {
239239
pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
240-
memcpy(pbBytes->bytes, [data bytes], data.length);
241-
pbBytes->size = (pb_size_t)data.length;
240+
if (pbBytes != NULL) {
241+
memcpy(pbBytes->bytes, [data bytes], data.length);
242+
pbBytes->size = (pb_size_t)data.length;
243+
}
242244
return pbBytes;
243245
}
244246

@@ -510,6 +512,9 @@ void FIRPopulateProtoWithInstalledServices(logs_proto_mobilesdk_ios_ICoreConfigu
510512
logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType *servicesInstalled =
511513
malloc(sizeof(logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType) *
512514
sdkServiceInstalledArray.count);
515+
if (servicesInstalled == NULL) {
516+
return;
517+
}
513518
for (NSUInteger i = 0; i < sdkServiceInstalledArray.count; i++) {
514519
NSNumber *typeEnum = sdkServiceInstalledArray[i];
515520
logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType serviceType =

Firebase/CoreDiagnostics/generate_project.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ readonly REPO_DIR="$( git rev-parse --show-toplevel )"
2222
exit 1
2323
}
2424

25-
pod gen "${REPO_DIR}/FirebaseCoreDiagnostics.podspec" --auto-open --gen-directory="${REPO_DIR}/gen" --local-sources="${REPO_DIR}/" --clean
25+
pod gen "${REPO_DIR}/FirebaseCoreDiagnostics.podspec" --auto-open --gen-directory="${REPO_DIR}/gen" --local-sources="${REPO_DIR}/" --platforms=ios,macos,tvos --clean

FirebaseCoreDiagnostics.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ non-Cocoapod integration. This library also respects the Firebase global data co
5252
s.dependency 'nanopb', '~> 0.3.901'
5353

5454
s.test_spec 'unit' do |unit_tests|
55+
unit_tests.platforms = {:ios => '8.0', :osx => '10.11', :tvos => '10.0'}
5556
unit_tests.platforms = {:ios => '8.0', :osx => '10.11', :tvos => '10.0'}
5657
unit_tests.dependency 'GoogleUtilities/UserDefaults', '~> 6.2'
5758
unit_tests.dependency 'OCMock'

GoogleDataTransportCCTSupport/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# v1.4.1
22
- Fixed a bug that would manifest if a proto ended up being > 16,320 bytes.
33
- Fix an Xcode 11.4 analyze error. (#4863)
4+
- Now checks the result of malloc. (#4871)
45

56
# v1.4.0
67
- Added the CSH backend and consolidated the CCT, FLL, and CSH backends.

GoogleDataTransportCCTSupport/GDTCCTLibrary/GDTCCTNanopbHelpers.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@
3939

4040
pb_bytes_array_t *GDTCCTEncodeData(NSData *data) {
4141
pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
42-
memcpy(pbBytes->bytes, [data bytes], data.length);
43-
pbBytes->size = (pb_size_t)data.length;
42+
if (pbBytes != NULL) {
43+
memcpy(pbBytes->bytes, [data bytes], data.length);
44+
pbBytes->size = (pb_size_t)data.length;
45+
}
4446
return pbBytes;
4547
}
4648

@@ -72,6 +74,9 @@ gdt_cct_BatchedLogRequest GDTCCTConstructBatchedLogRequest(
7274
gdt_cct_BatchedLogRequest batchedLogRequest = gdt_cct_BatchedLogRequest_init_default;
7375
NSUInteger numberOfLogRequests = logMappingIDToLogSet.count;
7476
gdt_cct_LogRequest *logRequests = malloc(sizeof(gdt_cct_LogRequest) * numberOfLogRequests);
77+
if (logRequests == NULL) {
78+
return batchedLogRequest;
79+
}
7580

7681
__block int i = 0;
7782
[logMappingIDToLogSet enumerateKeysAndObjectsUsingBlock:^(
@@ -102,6 +107,9 @@ gdt_cct_LogRequest GDTCCTConstructLogRequest(int32_t logSource,
102107
logRequest.client_info = GDTCCTConstructClientInfo();
103108
logRequest.has_client_info = 1;
104109
logRequest.log_event = malloc(sizeof(gdt_cct_LogEvent) * logSet.count);
110+
if (logRequest.log_event == NULL) {
111+
return logRequest;
112+
}
105113
int i = 0;
106114
for (GDTCORStoredEvent *log in logSet) {
107115
gdt_cct_LogEvent logEvent = GDTCCTConstructLogEvent(log);

0 commit comments

Comments
 (0)