From 07a749bc4798240576db362e23d03c2269b897da Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Mon, 27 Apr 2015 18:38:17 -0700 Subject: HDCP: buffer over flow check -- DO NOT MERGE bug: 20222489 Change-Id: I3a64a5999d68ea243d187f12ec7717b7f26d93a3 (cherry picked from commit 532cd7b86a5fdc7b9a30a45d8ae2d16ef7660a72) Conflicts: media/libmedia/IHDCP.cpp --- media/libmedia/IHDCP.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/media/libmedia/IHDCP.cpp b/media/libmedia/IHDCP.cpp index 493f5a4..3b42267 100644 --- a/media/libmedia/IHDCP.cpp +++ b/media/libmedia/IHDCP.cpp @@ -175,8 +175,19 @@ status_t BnHDCP::onTransact( case HDCP_ENCRYPT: { size_t size = data.readInt32(); + size_t bufSize = 2 * size; + + // watch out for overflow + void *inData = NULL; + if (bufSize > size) { + inData = malloc(bufSize); + } + + if (inData == NULL) { + reply->writeInt32(ERROR_OUT_OF_RANGE); + return OK; + } - void *inData = malloc(2 * size); void *outData = (uint8_t *)inData + size; data.read(inData, size); -- cgit v1.1