Correctly check buffer length in netlink_add_attribute()

This commit is contained in:
Martin Willi
2013-03-15 14:32:25 +01:00
parent 6ac601f543
commit 53c98f098f
2 changed files with 9 additions and 7 deletions
@@ -292,7 +292,7 @@ void netlink_add_attribute(struct nlmsghdr *hdr, int rta_type, chunk_t data,
{ {
struct rtattr *rta; struct rtattr *rta;
if (NLMSG_ALIGN(hdr->nlmsg_len) + RTA_ALIGN(data.len) > buflen) if (NLMSG_ALIGN(hdr->nlmsg_len) + RTA_LENGTH(data.len) > buflen)
{ {
DBG1(DBG_KNL, "unable to add attribute, buffer too small"); DBG1(DBG_KNL, "unable to add attribute, buffer too small");
return; return;
@@ -42,7 +42,8 @@ struct netlink_socket_t {
* @param out received netlink message * @param out received netlink message
* @param out_len length of the received message * @param out_len length of the received message
*/ */
status_t (*send)(netlink_socket_t *this, struct nlmsghdr *in, struct nlmsghdr **out, size_t *out_len); status_t (*send)(netlink_socket_t *this, struct nlmsghdr *in,
struct nlmsghdr **out, size_t *out_len);
/** /**
* Send a netlink message and wait for its acknowledge. * Send a netlink message and wait for its acknowledge.
@@ -72,6 +73,7 @@ netlink_socket_t *netlink_socket_create(int protocol);
* @param data data to add to the rtattr * @param data data to add to the rtattr
* @param buflen length of the netlink message buffer * @param buflen length of the netlink message buffer
*/ */
void netlink_add_attribute(struct nlmsghdr *hdr, int rta_type, chunk_t data, size_t buflen); void netlink_add_attribute(struct nlmsghdr *hdr, int rta_type, chunk_t data,
size_t buflen);
#endif /* KERNEL_NETLINK_SHARED_H_ */ #endif /* KERNEL_NETLINK_SHARED_H_ */