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

Commit acbc2ee4 authored by Keith Mok's avatar Keith Mok
Browse files

libnl++: Fix alignment problem

The memory alignemnt calculation is incorrect when adding request
with uint8_t data type.

Bug: 238756438
Test: Build, manual test
Change-Id: I4dae7ad337c6b8186e4ef0ae1fb5eb1e1463447d
parent 15a4f67a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ static nlattr* tail(nlmsghdr* msg) {

nlattr* MessageFactoryBase::add(nlmsghdr* msg, size_t maxLen, nlattrtype_t type, const void* data,
                                size_t dataLen) {
    const auto totalAttrLen = impl::space<nlattr>(dataLen);
    const auto newLen = impl::align(msg->nlmsg_len) + totalAttrLen;
    const auto totalAttrLen = impl::length<nlattr>(dataLen);
    const auto newLen = impl::align(msg->nlmsg_len) + impl::align(totalAttrLen);
    if (newLen > maxLen) {
        LOG(ERROR) << "Can't add attribute of size " << dataLen  //
                   << " - exceeded maxLen: " << newLen << " > " << maxLen;
+9 −1
Original line number Diff line number Diff line
@@ -35,12 +35,20 @@ constexpr size_t align(size_t len) {
    return (len + alignto - 1) & ~(alignto - 1);
}

/**
 * Equivalent to NLMSG_LENGTH(len).
 */
template <typename H>
constexpr size_t length(size_t len) {
    return align(sizeof(H)) + len;
}

/**
 * Equivalent to NLMSG_SPACE(len).
 */
template <typename H>
constexpr size_t space(size_t len) {
    return align(align(sizeof(H)) + len);
    return align(length<H>(len));
}

/**