diff options
| author | Lorenzo Colitti <lorenzo@google.com> | 2013-08-17 03:40:31 +0900 | 
|---|---|---|
| committer | Lorenzo Colitti <lorenzo@google.com> | 2013-11-20 10:29:19 +0900 | 
| commit | 96834569343f38dc006492fccdf6dad68521b005 (patch) | |
| tree | de25214ce391051de2bc492b4464eafa25c0203f /libsysutils | |
| parent | 381f70f52a282e6da780e4b686aaa9c230be2cdc (diff) | |
| download | system_core-96834569343f38dc006492fccdf6dad68521b005.zip system_core-96834569343f38dc006492fccdf6dad68521b005.tar.gz system_core-96834569343f38dc006492fccdf6dad68521b005.tar.bz2 | |
Get rid of an infinite loop in NetlinkEvent.cpp.
[Cherry-pick of 3984276ce47c965ad02a522280a139e0a0c7e5cf]
Bug: 10358527
Bug: 10263310
Bug: 10232006
Change-Id: I750e4bdf2000040adf214d6a772591d7bd25b350
Diffstat (limited to 'libsysutils')
| -rw-r--r-- | libsysutils/src/NetlinkEvent.cpp | 15 | 
1 files changed, 7 insertions, 8 deletions
| diff --git a/libsysutils/src/NetlinkEvent.cpp b/libsysutils/src/NetlinkEvent.cpp index b6da72f..01bec77 100644 --- a/libsysutils/src/NetlinkEvent.cpp +++ b/libsysutils/src/NetlinkEvent.cpp @@ -78,7 +78,7 @@ void NetlinkEvent::dump() {   */  bool NetlinkEvent::parseIfAddrMessage(int type, struct ifaddrmsg *ifaddr,                                        int rtasize) { -    struct rtattr *rta = IFA_RTA(ifaddr); +    struct rtattr *rta;      struct ifa_cacheinfo *cacheinfo = NULL;      char addrstr[INET6_ADDRSTRLEN] = ""; @@ -91,7 +91,8 @@ bool NetlinkEvent::parseIfAddrMessage(int type, struct ifaddrmsg *ifaddr,      // For log messages.      const char *msgtype = (type == RTM_NEWADDR) ? "RTM_NEWADDR" : "RTM_DELADDR"; -    while(RTA_OK(rta, rtasize)) { +    for (rta = IFA_RTA(ifaddr); RTA_OK(rta, rtasize); +         rta = RTA_NEXT(rta, rtasize)) {          if (rta->rta_type == IFA_ADDRESS) {              // Only look at the first address, because we only support notifying              // one change at a time. @@ -157,8 +158,6 @@ bool NetlinkEvent::parseIfAddrMessage(int type, struct ifaddrmsg *ifaddr,              asprintf(&mParams[6], "CSTAMP=%u", cacheinfo->cstamp);              asprintf(&mParams[7], "TSTAMP=%u", cacheinfo->tstamp);          } - -        rta = RTA_NEXT(rta, rtasize);      }      if (addrstr[0] == '\0') { @@ -173,10 +172,11 @@ bool NetlinkEvent::parseIfAddrMessage(int type, struct ifaddrmsg *ifaddr,   * Parse an binary message from a NETLINK_ROUTE netlink socket.   */  bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) { -    size_t sz = size; -    const struct nlmsghdr *nh = (struct nlmsghdr *) buffer; +    const struct nlmsghdr *nh; -    while (NLMSG_OK(nh, sz) && (nh->nlmsg_type != NLMSG_DONE)) { +    for (nh = (struct nlmsghdr *) buffer; +         NLMSG_OK(nh, size) && (nh->nlmsg_type != NLMSG_DONE); +         nh = NLMSG_NEXT(nh, size)) {          if (nh->nlmsg_type == RTM_NEWLINK) {              int len = nh->nlmsg_len - sizeof(*nh); @@ -245,7 +245,6 @@ bool NetlinkEvent::parseBinaryNetlinkMessage(char *buffer, int size) {          } else {                  SLOGD("Unexpected netlink message. type=0x%x\n", nh->nlmsg_type);          } -        nh = NLMSG_NEXT(nh, size);      }      return true; | 
