diff options
-rw-r--r-- | libs/binder/Parcel.cpp | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index ab2cdab21..694916cf1 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp | |||
@@ -719,25 +719,25 @@ restart_write: | |||
719 | 719 | ||
720 | status_t Parcel::writeByteVector(const std::vector<int8_t>& val) | 720 | status_t Parcel::writeByteVector(const std::vector<int8_t>& val) |
721 | { | 721 | { |
722 | status_t status; | ||
722 | if (val.size() > std::numeric_limits<int32_t>::max()) { | 723 | if (val.size() > std::numeric_limits<int32_t>::max()) { |
723 | return BAD_VALUE; | 724 | status = BAD_VALUE; |
725 | return status; | ||
724 | } | 726 | } |
725 | 727 | ||
726 | status_t status = writeInt32(val.size()); | 728 | status = writeInt32(val.size()); |
727 | |||
728 | if (status != OK) { | 729 | if (status != OK) { |
729 | return status; | 730 | return status; |
730 | } | 731 | } |
731 | 732 | ||
732 | for (const auto& item : val) { | 733 | void* data = writeInplace(val.size()); |
733 | status = writeByte(item); | 734 | if (!data) { |
734 | 735 | status = BAD_VALUE; | |
735 | if (status != OK) { | 736 | return status; |
736 | return status; | ||
737 | } | ||
738 | } | 737 | } |
739 | 738 | ||
740 | return OK; | 739 | memcpy(data, val.data(), val.size()); |
740 | return status; | ||
741 | } | 741 | } |
742 | 742 | ||
743 | status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val) | 743 | status_t Parcel::writeInt32Vector(const std::vector<int32_t>& val) |
@@ -1343,21 +1343,19 @@ status_t Parcel::readByteVector(std::vector<int8_t>* val) const { | |||
1343 | return status; | 1343 | return status; |
1344 | } | 1344 | } |
1345 | 1345 | ||
1346 | if (size < 0) { | 1346 | if (size < 0 || size_t(size) > dataAvail()) { |
1347 | return BAD_VALUE; | 1347 | status = BAD_VALUE; |
1348 | return status; | ||
1348 | } | 1349 | } |
1349 | 1350 | const void* data = readInplace(size); | |
1350 | val->resize(size); | 1351 | if (!data) { |
1351 | 1352 | status = BAD_VALUE; | |
1352 | for (auto& v : *val) { | 1353 | return status; |
1353 | status = readByte(&v); | ||
1354 | |||
1355 | if (status != OK) { | ||
1356 | return status; | ||
1357 | } | ||
1358 | } | 1354 | } |
1355 | val->resize(size); | ||
1356 | memcpy(val->data(), data, size); | ||
1359 | 1357 | ||
1360 | return OK; | 1358 | return status; |
1361 | } | 1359 | } |
1362 | 1360 | ||
1363 | status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const { | 1361 | status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const { |