Skip to content

Commit 984d7ac

Browse files
Nate MyrenGerrit Code Review
authored andcommitted
Merge "[Binder][XIAOMI][Bugfix] Skip appops header in native parcel. [2/2]" into main
2 parents 51b2f8f + edee03a commit 984d7ac

2 files changed

Lines changed: 43 additions & 14 deletions

File tree

libs/binder/Status.cpp

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,28 @@ status_t Status::readFromParcel(const Parcel& parcel) {
9999
return status;
100100
}
101101

102-
// Skip over fat response headers. Not used (or propagated) in native code.
103-
if (mException == EX_HAS_REPLY_HEADER) {
104-
// Note that the header size includes the 4 byte size field.
105-
const size_t header_start = parcel.dataPosition();
106-
// Get available size before reading more
107-
const size_t header_avail = parcel.dataAvail();
108-
109-
int32_t header_size;
110-
status = parcel.readInt32(&header_size);
102+
if (mException == EX_HAS_NOTED_APPOPS_REPLY_HEADER) {
103+
status = skipUnusedHeader(parcel);
104+
if (status != OK) {
105+
setFromStatusT(status);
106+
return status;
107+
}
108+
// Read next exception code.
109+
status = parcel.readInt32(&mException);
111110
if (status != OK) {
112111
setFromStatusT(status);
113112
return status;
114113
}
114+
}
115115

116-
if (header_size < 0 || static_cast<size_t>(header_size) > header_avail) {
117-
android_errorWriteLog(0x534e4554, "132650049");
118-
setFromStatusT(UNKNOWN_ERROR);
119-
return UNKNOWN_ERROR;
116+
// Skip over fat response headers. Not used (or propagated) in native code.
117+
if (mException == EX_HAS_REPLY_HEADER) {
118+
status = skipUnusedHeader(parcel);
119+
if (status != OK) {
120+
setFromStatusT(status);
121+
return status;
120122
}
121123

122-
parcel.setDataPosition(header_start + header_size);
123124
// And fat response headers are currently only used when there are no
124125
// exceptions, so act like there was no error.
125126
mException = EX_NONE;
@@ -257,5 +258,28 @@ String8 Status::toString8() const {
257258
return ret;
258259
}
259260

261+
status_t Status::skipUnusedHeader(const Parcel& parcel) {
262+
// Note that the header size includes the 4 byte size field.
263+
const size_t header_start = parcel.dataPosition();
264+
// Get available size before reading more
265+
const size_t header_avail = parcel.dataAvail();
266+
267+
int32_t header_size;
268+
status_t status = parcel.readInt32(&header_size);
269+
ALOGD("Skip unused header. exception code: %d, start: %zu, size: %d.",
270+
mException, header_start, header_size);
271+
if (status != OK) {
272+
return status;
273+
}
274+
275+
if (header_size < 0 || static_cast<size_t>(header_size) > header_avail) {
276+
android_errorWriteLog(0x534e4554, "132650049");
277+
return UNKNOWN_ERROR;
278+
}
279+
280+
parcel.setDataPosition(header_start + header_size);
281+
return OK;
282+
}
283+
260284
} // namespace binder
261285
} // namespace android

libs/binder/include/binder/Status.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class LIBBINDER_EXPORTED Status final {
6767
EX_SERVICE_SPECIFIC = -8,
6868
EX_PARCELABLE = -9,
6969

70+
// See android/os/Parcel.java. We need to handle this in native code.
71+
EX_HAS_NOTED_APPOPS_REPLY_HEADER = -127,
72+
7073
// This is special and Java specific; see Parcel.java.
7174
EX_HAS_REPLY_HEADER = -128,
7275
// This is special, and indicates to C++ binder proxies that the
@@ -150,6 +153,8 @@ class LIBBINDER_EXPORTED Status final {
150153
Status(int32_t exceptionCode, int32_t errorCode);
151154
Status(int32_t exceptionCode, int32_t errorCode, const String8& message);
152155

156+
status_t skipUnusedHeader(const Parcel& parcel);
157+
153158
// If |mException| == EX_TRANSACTION_FAILED, generated code will return
154159
// |mErrorCode| as the result of the transaction rather than write an
155160
// exception to the reply parcel.

0 commit comments

Comments
 (0)