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
diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp
index c2ba647..86c1f42 100644
--- a/libsysutils/src/NetlinkEvent.cpp
+++ b/libsysutils/src/NetlinkEvent.cpp
@@ -93,13 +93,11 @@
}
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);