Skip to content

Commit 47f6fe8

Browse files
AquilesCantaJoker-V2
authored andcommitted
Prevent read of uninitialized memory
Bug: 173720767 Test: atest IMediaPlayerTest Change-Id: Ib6a3d24e07915e8af9d019e54d0501b74aa4671d Merged-In: Ib6a3d24e07915e8af9d019e54d0501b74aa4671d (cherry picked from commit 42a97f5648e9345461422310039fc9d1def0a91a) (cherry picked from commit f8c7ecf6567635062ccb262b0d1e58486420aad1)
1 parent 042489a commit 47f6fe8

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

media/libmedia/IMediaPlayer.cpp

+35-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
#include <arpa/inet.h>
1919
#include <stdint.h>
20-
#include <sys/types.h>
2120

21+
#include <binder/IPCThreadState.h>
2222
#include <binder/Parcel.h>
2323

2424
#include <media/AudioResamplerPublic.h>
@@ -85,10 +85,36 @@ enum {
8585
};
8686

8787
// ModDrm helpers
88-
static void readVector(const Parcel& reply, Vector<uint8_t>& vector) {
89-
uint32_t size = reply.readUint32();
90-
vector.insertAt((size_t)0, size);
91-
reply.read(vector.editArray(), size);
88+
static status_t readVector(const Parcel& reply, Vector<uint8_t>& vector) {
89+
uint32_t size = 0;
90+
status_t status = reply.readUint32(&size);
91+
if (status == OK) {
92+
status = size <= reply.dataAvail() ? OK : BAD_VALUE;
93+
}
94+
if (status == OK) {
95+
status = vector.insertAt((size_t) 0, size) >= 0 ? OK : NO_MEMORY;
96+
}
97+
if (status == OK) {
98+
status = reply.read(vector.editArray(), size);
99+
}
100+
if (status != OK) {
101+
char errorMsg[100];
102+
char buganizerId[] = "173720767";
103+
snprintf(errorMsg,
104+
sizeof(errorMsg),
105+
"%s: failed to read array. Size: %d, status: %d.",
106+
__func__,
107+
size,
108+
status);
109+
android_errorWriteWithInfoLog(
110+
/* safetyNet tag= */ 0x534e4554,
111+
buganizerId,
112+
IPCThreadState::self()->getCallingUid(),
113+
errorMsg,
114+
strlen(errorMsg));
115+
ALOGE("%s (b/%s)", errorMsg, buganizerId);
116+
}
117+
return status;
92118
}
93119

94120
static void writeVector(Parcel& data, Vector<uint8_t> const& vector) {
@@ -964,8 +990,10 @@ status_t BnMediaPlayer::onTransact(
964990
uint8_t uuid[16];
965991
data.read(uuid, sizeof(uuid));
966992
Vector<uint8_t> drmSessionId;
967-
readVector(data, drmSessionId);
968-
993+
status_t status = readVector(data, drmSessionId);
994+
if (status != OK) {
995+
return status;
996+
}
969997
uint32_t result = prepareDrm(uuid, drmSessionId);
970998
reply->writeInt32(result);
971999
return OK;

0 commit comments

Comments
 (0)