Add safe check for mtp_data_header
header is initialized using mIobuf[0].bufs.data(). If mIobuf[0].bufs is NULL, dereferencing header could produce NPE.
Bug: 244106060
Change-Id: I8ca9c4a8c433bb1935879148d918ba6e120d5aa9
Test: presubmit
diff --git a/media/mtp/MtpFfsHandle.cpp b/media/mtp/MtpFfsHandle.cpp
index ef8c9aa..5d68890 100644
--- a/media/mtp/MtpFfsHandle.cpp
+++ b/media/mtp/MtpFfsHandle.cpp
@@ -591,6 +591,9 @@
// Send the header data
mtp_data_header *header = reinterpret_cast<mtp_data_header*>(mIobuf[0].bufs.data());
+ if (header == NULL) {
+ return -1;
+ }
header->length = htole32(given_length);
header->type = htole16(2); // data packet
header->command = htole16(mfr.command);