Skip to content

Commit 86189f7

Browse files
authored
Address a few potential security issues (#5059)
* Address a few potential security issues Eliminates use of memcpy and malloc * Update CHANGELOG
1 parent 6628b41 commit 86189f7

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

Firebase/CoreDiagnostics/CHANGELOG.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
# v1.2.1
1+
# v1.2.3
2+
- Remove usage of memcpy and convert calls from malloc to calloc.
3+
4+
# v1.2.2
25
- Fixed a bug that would manifest if a proto ended up being > 16,320 bytes.
6+
7+
# v1.2.2
38
- Now checks the result of malloc. (#4872)
49

510
# v1.2.0

Firebase/CoreDiagnostics/FIRCDLibrary/FIRCoreDiagnostics.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ + (NSString *)deviceModel {
220220

221221
#pragma mark - nanopb helper functions
222222

223-
/** Mallocs a pb_bytes_array and copies the given NSString's bytes into the bytes array.
223+
/** Callocs a pb_bytes_array and copies the given NSString's bytes into the bytes array.
224224
*
225225
* @note Memory needs to be free manually, through pb_free or pb_release.
226226
* @param string The string to encode as pb_bytes.
@@ -230,15 +230,15 @@ + (NSString *)deviceModel {
230230
returnFIREncodeData(stringBytes);
231231
}
232232

233-
/** Mallocs a pb_bytes_array and copies the given NSData bytes into the bytes array.
233+
/** Callocs a pb_bytes_array and copies the given NSData bytes into the bytes array.
234234
*
235235
* @note Memory needs to be free manually, through pb_free or pb_release.
236236
* @param data The data to copy into the new bytes array.
237237
*/
238238
pb_bytes_array_t *FIREncodeData(NSData *data) {
239-
pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
239+
pb_bytes_array_t *pbBytes = calloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length), 1);
240240
if (pbBytes != NULL) {
241-
memcpy(pbBytes->bytes, [data bytes], data.length);
241+
[data getBytes:pbBytes range:NSMakeRange(0, data.length)];
242242
pbBytes->size = (pb_size_t)data.length;
243243
}
244244
return pbBytes;
@@ -510,7 +510,7 @@ void FIRPopulateProtoWithInstalledServices(logs_proto_mobilesdk_ios_ICoreConfigu
510510
}
511511

512512
logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType *servicesInstalled =
513-
malloc(sizeof(logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType) *
513+
calloc(sizeof(logs_proto_mobilesdk_ios_ICoreConfiguration_ServiceType),
514514
sdkServiceInstalledArray.count);
515515
if (servicesInstalled == NULL) {
516516
return;

GoogleDataTransportCCTSupport/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v2.0.1
2+
- Remove usage of memcpy and convert calls from malloc to calloc.
3+
14
# v2.0.0
25
- Adds a sentinel value to GDTCOREvent's custom params to signal collection
36
of current network info to be associated with some event. This is required

GoogleDataTransportCCTSupport/GDTCCTLibrary/GDTCCTNanopbHelpers.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
}
4444

4545
pb_bytes_array_t *GDTCCTEncodeData(NSData *data) {
46-
pb_bytes_array_t *pbBytes = malloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length));
46+
pb_bytes_array_t *pbBytes = calloc(PB_BYTES_ARRAY_T_ALLOCSIZE(data.length), 1);
4747
if (pbBytes != NULL) {
48-
memcpy(pbBytes->bytes, [data bytes], data.length);
48+
[data getBytes:pbBytes range:NSMakeRange(0, data.length)];
4949
pbBytes->size = (pb_size_t)data.length;
5050
}
5151
return pbBytes;
@@ -78,7 +78,7 @@ gdt_cct_BatchedLogRequest GDTCCTConstructBatchedLogRequest(
7878
NSDictionary<NSString *, NSSet<GDTCOREvent *> *> *logMappingIDToLogSet) {
7979
gdt_cct_BatchedLogRequest batchedLogRequest = gdt_cct_BatchedLogRequest_init_default;
8080
NSUInteger numberOfLogRequests = logMappingIDToLogSet.count;
81-
gdt_cct_LogRequest *logRequests = malloc(sizeof(gdt_cct_LogRequest) * numberOfLogRequests);
81+
gdt_cct_LogRequest *logRequests = calloc(sizeof(gdt_cct_LogRequest), numberOfLogRequests);
8282
if (logRequests == NULL) {
8383
return batchedLogRequest;
8484
}
@@ -111,7 +111,7 @@ gdt_cct_LogRequest GDTCCTConstructLogRequest(int32_t logSource,
111111
logRequest.has_log_source = 1;
112112
logRequest.client_info = GDTCCTConstructClientInfo();
113113
logRequest.has_client_info = 1;
114-
logRequest.log_event = malloc(sizeof(gdt_cct_LogEvent) * logSet.count);
114+
logRequest.log_event = calloc(sizeof(gdt_cct_LogEvent), logSet.count);
115115
if (logRequest.log_event == NULL) {
116116
return logRequest;
117117
}

GoogleDataTransportCCTSupport/GDTCCTLibrary/Private/GDTCCTNanopbHelpers.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ FOUNDATION_EXPORT NSString *const GDTCCTNetworkConnectionInfo;
3737

3838
/** Converts an NSString* to a pb_bytes_array_t*.
3939
*
40-
* @note malloc is called in this method. Ensure that pb_release is called on this or the parent.
40+
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
4141
*
4242
* @param string The string to convert.
4343
* @return A newly allocated array of bytes representing the UTF8 encoding of the string.
@@ -46,7 +46,7 @@ pb_bytes_array_t *GDTCCTEncodeString(NSString *string);
4646

4747
/** Converts an NSData to a pb_bytes_array_t*.
4848
*
49-
* @note malloc is called in this method. Ensure that pb_release is called on this or the parent.
49+
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
5050
*
5151
* @param data The data to convert.
5252
* @return A newly allocated array of bytes with [data bytes] copied into it.
@@ -67,7 +67,7 @@ NSData *GDTCCTEncodeBatchedLogRequest(gdt_cct_BatchedLogRequest *batchedLogReque
6767

6868
/** Constructs a gdt_cct_BatchedLogRequest given sets of events segemented by mapping ID.
6969
*
70-
* @note malloc is called in this method. Ensure that pb_release is called on this or the parent.
70+
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
7171
*
7272
* @param logMappingIDToLogSet A map of mapping IDs to sets of events to convert into a batch.
7373
* @return A newly created gdt_cct_BatchedLogRequest.
@@ -78,7 +78,7 @@ gdt_cct_BatchedLogRequest GDTCCTConstructBatchedLogRequest(
7878

7979
/** Constructs a log request given a log source and a set of events.
8080
*
81-
* @note malloc is called in this method. Ensure that pb_release is called on this or the parent.
81+
* @note calloc is called in this method. Ensure that pb_release is called on this or the parent.
8282
* @param logSource The CCT log source to put into the log request.
8383
* @param logSet The set of events to send in this log request.
8484
*/
@@ -126,7 +126,7 @@ gdt_cct_NetworkConnectionInfo_MobileSubtype GDTCCTNetworkConnectionInfoNetworkMo
126126

127127
/** Decodes a gdt_cct_LogResponse given proto bytes.
128128
*
129-
* @note malloc is called in this method. Ensure that pb_release is called on the return value.
129+
* @note calloc is called in this method. Ensure that pb_release is called on the return value.
130130
*
131131
* @param data The proto bytes of the gdt_cct_LogResponse.
132132
* @param error An error that will be populated if something went wrong during decoding.

0 commit comments

Comments
 (0)
close