Check size of grantors before indexing into the vec
It's possible that the MQDescriptor was created with no grantors or an
incorrect amount.
Test: atest hidl_test
Bug: 233680266
Change-Id: Id0c69dbc5827202f834e0f6f1a9bf39395e8b597
diff --git a/base/include/hidl/MQDescriptor.h b/base/include/hidl/MQDescriptor.h
index 0429444..38ac325 100644
--- a/base/include/hidl/MQDescriptor.h
+++ b/base/include/hidl/MQDescriptor.h
@@ -181,7 +181,11 @@
template<typename T, MQFlavor flavor>
size_t MQDescriptor<T, flavor>::getSize() const {
- return static_cast<size_t>(mGrantors[details::DATAPTRPOS].extent);
+ if (mGrantors.size() > details::DATAPTRPOS) {
+ return static_cast<size_t>(mGrantors[details::DATAPTRPOS].extent);
+ } else {
+ return 0;
+ }
}
template<typename T, MQFlavor flavor>