christgau / wsdd

A Web Service Discovery host daemon.
MIT License
841 stars 99 forks source link

Incorrect offset calculation in netlink_monitor.py #77

Closed shotahino closed 3 years ago

shotahino commented 3 years ago

I believe this is attempting to compute the offset at the next word boundary. This is incorrect.

https://github.com/christgau/wsdd/blob/master/test/netlink_monitor.py#L65

       if h_type != RTM_NEWADDR and h_type != RTM_DELADDR:
            offset += ((msg_len + 1) // NLM_HDR_ALIGNTO) * NLM_HDR_ALIGNTO
            # print('not interested in message type ', h_type)
            # print('new offset: ', offset)
            continue

if msg_len is 1, offset would be incremented by 0. This is incorrect. We would want to increment the offset by 4 so the next offset is word aligned.

The correct way to increment the offset would be

 offset += ((msg_len + NLM_HDR_ALIGNTO - 1) // NLM_HDR_ALIGNTO) * NLM_HDR_ALIGNTO

The same bug is also in https://github.com/christgau/wsdd/blob/master/test/netlink_monitor.py#L92

christgau commented 3 years ago

D'oh! You're right. This might be the reason for #59. Will fix it.

Thanks a lot for pointing that one out!