diff options
author | Eric Laurent <elaurent@google.com> | 2015-02-06 22:22:33 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-06 22:22:33 +0000 |
commit | cdb5305e4966e9ee85a9d0809e4e7b2c4e8f7866 (patch) | |
tree | dbdef35e85000a08fd3d97b7e203234c0c798ba9 /media | |
parent | 9f1f00cee228eb1c6cf4a7e2b9dc4c92d6754a39 (diff) | |
parent | 1d670b11313250442455a22f1056ad649d607fb2 (diff) | |
download | frameworks_av-cdb5305e4966e9ee85a9d0809e4e7b2c4e8f7866.zip frameworks_av-cdb5305e4966e9ee85a9d0809e4e7b2c4e8f7866.tar.gz frameworks_av-cdb5305e4966e9ee85a9d0809e4e7b2c4e8f7866.tar.bz2 |
Merge "audio policy service: fix possible memory overflow"
Diffstat (limited to 'media')
-rw-r--r-- | media/libmedia/IAudioPolicyService.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/media/libmedia/IAudioPolicyService.cpp b/media/libmedia/IAudioPolicyService.cpp index b175055..f2ff27b 100644 --- a/media/libmedia/IAudioPolicyService.cpp +++ b/media/libmedia/IAudioPolicyService.cpp @@ -73,6 +73,8 @@ enum { REGISTER_POLICY_MIXES, }; +#define MAX_ITEMS_PER_LIST 1024 + class BpAudioPolicyService : public BpInterface<IAudioPolicyService> { public: @@ -1058,10 +1060,18 @@ status_t BnAudioPolicyService::onTransact( audio_port_role_t role = (audio_port_role_t)data.readInt32(); audio_port_type_t type = (audio_port_type_t)data.readInt32(); unsigned int numPortsReq = data.readInt32(); + if (numPortsReq > MAX_ITEMS_PER_LIST) { + numPortsReq = MAX_ITEMS_PER_LIST; + } unsigned int numPorts = numPortsReq; - unsigned int generation; struct audio_port *ports = (struct audio_port *)calloc(numPortsReq, sizeof(struct audio_port)); + if (ports == NULL) { + reply->writeInt32(NO_MEMORY); + reply->writeInt32(0); + return NO_ERROR; + } + unsigned int generation; status_t status = listAudioPorts(role, type, &numPorts, ports, &generation); reply->writeInt32(status); reply->writeInt32(numPorts); @@ -1115,11 +1125,19 @@ status_t BnAudioPolicyService::onTransact( case LIST_AUDIO_PATCHES: { CHECK_INTERFACE(IAudioPolicyService, data, reply); unsigned int numPatchesReq = data.readInt32(); + if (numPatchesReq > MAX_ITEMS_PER_LIST) { + numPatchesReq = MAX_ITEMS_PER_LIST; + } unsigned int numPatches = numPatchesReq; - unsigned int generation; struct audio_patch *patches = (struct audio_patch *)calloc(numPatchesReq, sizeof(struct audio_patch)); + if (patches == NULL) { + reply->writeInt32(NO_MEMORY); + reply->writeInt32(0); + return NO_ERROR; + } + unsigned int generation; status_t status = listAudioPatches(&numPatches, patches, &generation); reply->writeInt32(status); reply->writeInt32(numPatches); |