From 86dd1d41af2bd5c53a996789a0a793dea65d2b04 Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Thu, 28 Jan 2010 15:29:43 +0000 Subject: [PATCH] Handle zero-length iovecs in multicast messages This commit was SVN r22507. --- orte/mca/rmcast/tcp/rmcast_tcp.c | 27 ++++++++++++++++----------- orte/mca/rmcast/udp/rmcast_udp.c | 27 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/orte/mca/rmcast/tcp/rmcast_tcp.c b/orte/mca/rmcast/tcp/rmcast_tcp.c index 404624ac6c..7fe636156d 100644 --- a/orte/mca/rmcast/tcp/rmcast_tcp.c +++ b/orte/mca/rmcast/tcp/rmcast_tcp.c @@ -383,10 +383,12 @@ process: ORTE_ERROR_LOG(rc); goto cleanup; } - /* pack the bytes */ - if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, snd->iovec_array[sz].iov_base, tmp32, OPAL_UINT8))) { - ORTE_ERROR_LOG(rc); - goto cleanup; + if (0 < tmp32) { + /* pack the bytes */ + if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, snd->iovec_array[sz].iov_base, tmp32, OPAL_UINT8))) { + ORTE_ERROR_LOG(rc); + goto cleanup; + } } } @@ -978,14 +980,17 @@ static void process_recv(int fd, short event, void *cbdata) ORTE_ERROR_LOG(rc); goto cleanup; } - /* allocate the space */ - iovec_array[i].iov_base = (uint8_t*)malloc(sz); + iovec_array[i].iov_base = NULL; iovec_array[i].iov_len = sz; - /* unpack the data */ - if (ORTE_SUCCESS != (rc = opal_dss.unpack(buf, iovec_array[i].iov_base, &sz, OPAL_UINT8))) { - ORTE_ERROR_LOG(rc); - goto cleanup; - } + if (0 < sz) { + /* allocate the space */ + iovec_array[i].iov_base = (uint8_t*)malloc(sz); + /* unpack the data */ + if (ORTE_SUCCESS != (rc = opal_dss.unpack(buf, iovec_array[i].iov_base, &sz, OPAL_UINT8))) { + ORTE_ERROR_LOG(rc); + goto cleanup; + } + } } } else if (1 == flag && NULL == recvd_buf) { /* buffer was included */ diff --git a/orte/mca/rmcast/udp/rmcast_udp.c b/orte/mca/rmcast/udp/rmcast_udp.c index 930001c63c..32bed77fbb 100644 --- a/orte/mca/rmcast/udp/rmcast_udp.c +++ b/orte/mca/rmcast/udp/rmcast_udp.c @@ -872,14 +872,17 @@ static void process_recv(int fd, short event, void *cbdata) ORTE_ERROR_LOG(rc); goto cleanup; } - /* allocate the space */ - iovec_array[i].iov_base = (uint8_t*)malloc(sz); + iovec_array[i].iov_base = NULL; iovec_array[i].iov_len = sz; - /* unpack the data */ - if (ORTE_SUCCESS != (rc = opal_dss.unpack(&buf, iovec_array[i].iov_base, &sz, OPAL_UINT8))) { - ORTE_ERROR_LOG(rc); - goto cleanup; - } + if (0 < sz) { + /* allocate the space */ + iovec_array[i].iov_base = (uint8_t*)malloc(sz); + /* unpack the data */ + if (ORTE_SUCCESS != (rc = opal_dss.unpack(&buf, iovec_array[i].iov_base, &sz, OPAL_UINT8))) { + ORTE_ERROR_LOG(rc); + goto cleanup; + } + } } } else if (1 == flag && NULL == recvd_buf) { /* buffer was included */ @@ -1220,10 +1223,12 @@ static void xmit_data(int sd, short flags, void* send_req) ORTE_ERROR_LOG(rc); goto CLEANUP; } - /* pack the bytes */ - if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, snd->iovec_array[sz].iov_base, tmp32, OPAL_UINT8))) { - ORTE_ERROR_LOG(rc); - goto CLEANUP; + if (0 < tmp32) { + /* pack the bytes */ + if (ORTE_SUCCESS != (rc = opal_dss.pack(&buf, snd->iovec_array[sz].iov_base, tmp32, OPAL_UINT8))) { + ORTE_ERROR_LOG(rc); + goto CLEANUP; + } } }