iscsi-scstd: Make sure that the buffer allocated for nl_read() is large enough (merged r4109 and r4110 from trunk)

git-svn-id: http://svn.code.sf.net/p/scst/svn/branches/2.2.x@4125 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Bart Van Assche
2012-02-13 19:22:01 +00:00
parent 985d0e7c4d
commit 55ea8b70c1
+10 -4
View File
@@ -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)