Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fb1f4cf4 authored by Christopher Wiley's avatar Christopher Wiley Committed by android-build-merger
Browse files

Merge "libbinder: Return UNEXPECTED_NULL when appropriate"

am: 41e50f99

* commit '41e50f99':
  libbinder: Return UNEXPECTED_NULL when appropriate
parents 877b5dae 41e50f99
Loading
Loading
Loading
Loading
+48 −175
Original line number Original line Diff line number Diff line
@@ -338,6 +338,39 @@ status_t unflatten_binder(const sp<ProcessState>& proc,
    return BAD_TYPE;
    return BAD_TYPE;
}
}


namespace {

template<typename T>
status_t readTypedVector(std::vector<T>* val, const Parcel* p,
                         status_t(Parcel::*read_func)(T*) const) {
    val->clear();

    int32_t size;
    status_t status = p->readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return UNEXPECTED_NULL;
    }

    val->resize(size);

    for (auto& v: *val) {
        status = (p->*read_func)(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}

}  // namespace

// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------


Parcel::Parcel()
Parcel::Parcel()
@@ -1097,30 +1130,7 @@ status_t Parcel::writeStrongBinderVector(const std::vector<sp<IBinder>>& val)
}
}


status_t Parcel::readStrongBinderVector(std::vector<sp<IBinder>>* val) const {
status_t Parcel::readStrongBinderVector(std::vector<sp<IBinder>>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readStrongBinder);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v : *val) {
        status = readStrongBinder(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::writeWeakBinder(const wp<IBinder>& val)
status_t Parcel::writeWeakBinder(const wp<IBinder>& val)
@@ -1419,10 +1429,15 @@ status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
        return status;
        return status;
    }
    }


    if (size < 0 || size_t(size) > dataAvail()) {
    if (size < 0) {
        status = UNEXPECTED_NULL;
        return status;
    }
    if (size_t(size) > dataAvail()) {
        status = BAD_VALUE;
        status = BAD_VALUE;
        return status;
        return status;
    }
    }

    const void* data = readInplace(size);
    const void* data = readInplace(size);
    if (!data) {
    if (!data) {
        status = BAD_VALUE;
        status = BAD_VALUE;
@@ -1435,111 +1450,19 @@ status_t Parcel::readByteVector(std::vector<int8_t>* val) const {
}
}


status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const {
status_t Parcel::readInt32Vector(std::vector<int32_t>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readInt32);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v: *val) {
        status = readInt32(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::readInt64Vector(std::vector<int64_t>* val) const {
status_t Parcel::readInt64Vector(std::vector<int64_t>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readInt64);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v : *val) {
        status = readInt64(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::readFloatVector(std::vector<float>* val) const {
status_t Parcel::readFloatVector(std::vector<float>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readFloat);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v : *val) {
        status = readFloat(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::readDoubleVector(std::vector<double>* val) const {
status_t Parcel::readDoubleVector(std::vector<double>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readDouble);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v : *val) {
        status = readDouble(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::readBoolVector(std::vector<bool>* val) const {
status_t Parcel::readBoolVector(std::vector<bool>* val) const {
@@ -1553,7 +1476,7 @@ status_t Parcel::readBoolVector(std::vector<bool>* val) const {
    }
    }


    if (size < 0) {
    if (size < 0) {
        return BAD_VALUE;
        return UNEXPECTED_NULL;
    }
    }


    val->resize(size);
    val->resize(size);
@@ -1575,61 +1498,11 @@ status_t Parcel::readBoolVector(std::vector<bool>* val) const {
}
}


status_t Parcel::readCharVector(std::vector<char16_t>* val) const {
status_t Parcel::readCharVector(std::vector<char16_t>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readChar);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->resize(size);

    for (auto& v : *val) {
        status = readChar(&v);

        if (status != OK) {
            return status;
        }
    }

    return OK;
}
}


status_t Parcel::readString16Vector(std::vector<String16>* val) const {
status_t Parcel::readString16Vector(std::vector<String16>* val) const {
    val->clear();
    return readTypedVector(val, this, &Parcel::readString16);

    int32_t size;
    status_t status = readInt32(&size);

    if (status != OK) {
        return status;
    }

    if (size < 0) {
        return BAD_VALUE;
    }

    val->reserve(size);

    while (size-- > 0) {
        const char16_t *data;
        size_t size;
        data = readString16Inplace(&size);

        if (data == nullptr) {
            return UNKNOWN_ERROR;
        }

        val->emplace_back(data, size);
    }

    return OK;
}
}




@@ -1836,7 +1709,7 @@ status_t Parcel::readString16(String16* pArg) const
        return 0;
        return 0;
    } else {
    } else {
        *pArg = String16();
        *pArg = String16();
        return UNKNOWN_ERROR;
        return UNEXPECTED_NULL;
    }
    }
}
}