diff --git a/iscsi-scst/usr/event.c b/iscsi-scst/usr/event.c index 179e76cbc..8d19d0750 100644 --- a/iscsi-scst/usr/event.c +++ b/iscsi-scst/usr/event.c @@ -37,6 +37,8 @@ #define ISCSI_ISNS_SYSFS_ACCESS_CONTROL_ENABLED "AccessControl" +#define STATIC_ASSERT(e) ((void)sizeof(int[1-2*!(e)])) + static struct sockaddr_nl src_addr, dest_addr; static int nl_write(int fd, void *data, int len) @@ -158,7 +160,8 @@ static int handle_e_add_target(int fd, const struct iscsi_kern_event *event) /* Params are not 0-terminated */ - size = strlen("Target ") + event->param1_size + 2 + event->param2_size + 1; + size = strlen("Target ") + event->param1_size + 2 + event->param2_size + + 1 + NLMSG_ALIGNTO - 1; buf = malloc(size); if (buf == NULL) { @@ -397,7 +400,7 @@ static int handle_e_mgmt_cmd(int fd, const struct iscsi_kern_event *event) /* Params are not 0-terminated */ - size = event->param1_size + 1; + size = NLMSG_ALIGN(event->param1_size + 1); buf = malloc(size); if (buf == NULL) { @@ -486,7 +489,7 @@ static int handle_e_get_attr_value(int fd, const struct iscsi_kern_event *event) /* Params are not 0-terminated */ - size = event->param1_size + 1; + size = NLMSG_ALIGN(event->param1_size + 1); buf = malloc(size); if (buf == NULL) { @@ -749,7 +752,8 @@ static int handle_e_set_attr_value(int fd, const struct iscsi_kern_event *event) } /* Params are not 0-terminated */ - size = event->param1_size + 1 + 1 + event->param2_size + 1; + size = event->param1_size + 1 + 1 + event->param2_size + 1 + + NLMSG_ALIGNTO - 1; buf = malloc(size); if (buf == NULL) { @@ -1037,6 +1041,8 @@ int handle_iscsi_events(int fd, bool wait) * but IET developers thought it's OK. ToDo: fix somewhen. */ + STATIC_ASSERT(sizeof(event) % NLMSG_ALIGNTO == 0); + retry: if ((rc = nl_read(fd, &event, sizeof(event), wait)) < 0) { if (errno == EAGAIN)