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

Commit 80ec37aa authored by Chih-Wei Huang's avatar Chih-Wei Huang
Browse files

libsysutils: reimplement NetlinkEvent::findParam in the proper way

The original implementation can not find correct parameters for certain
cases. For example, if you have both foo_bar and foo, try to find foo
may be mismatched. The correct way is to match with "=".

Change-Id: I403b1a7b889583a57a4f3a14e575181ce93b10ff
parent 07b3d09e
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -93,13 +93,11 @@ bool NetlinkEvent::decode(char *buffer, int size) {
}

const char *NetlinkEvent::findParam(const char *paramName) {
    int i;

    for (i = 0; i < NL_PARAMS_MAX; i++) {
        if (!mParams[i])
            break;
        if (!strncmp(mParams[i], paramName, strlen(paramName)))
            return &mParams[i][strlen(paramName) + 1];
    size_t len = strlen(paramName);
    for (int i = 0; mParams[i] && i < NL_PARAMS_MAX; ++i) {
        const char *ptr = mParams[i] + len;
        if (!strncmp(mParams[i], paramName, len) && *ptr == '=')
            return ++ptr;
    }

    SLOGE("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName);