From 63d17ce90150818feaa1798a7de4d108e086b9e2 Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Thu, 21 Mar 2013 16:05:50 +0000 Subject: [PATCH] Fix CID 968581: ensure that the string read from the socket is always \0-terminated so that strlen() and strstr() can be used without fear. Also fix some insignificant mem leaks (which is somewhat moot, because as soon as we leave those error conditions, the process will be terminating, but what the heck, might as well fix these while I was in the file for the \0-termination issue...). This commit was SVN r28199. --- orte/mca/ras/slurm/ras_slurm_module.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/orte/mca/ras/slurm/ras_slurm_module.c b/orte/mca/ras/slurm/ras_slurm_module.c index 2df65b0228..3509418594 100644 --- a/orte/mca/ras/slurm/ras_slurm_module.c +++ b/orte/mca/ras/slurm/ras_slurm_module.c @@ -35,6 +35,7 @@ #endif #include #include +#include #include "opal/util/argv.h" #include "opal/util/net.h" @@ -751,7 +752,8 @@ static void recv_data(int fd, short args, void *cbdata) /* read the data from the socket and put it in the * nodes field of op */ - nbytes = read(fd, recv_msg, 8192); + memset(recv_msg, 0, sizeof(recv_msg)); + nbytes = read(fd, recv_msg, sizeof(recv_msg) - 1); opal_output_verbose(2, orte_ras_base.ras_output, "%s ras:slurm: dynamic allocation msg: %s", @@ -763,7 +765,7 @@ static void recv_data(int fd, short args, void *cbdata) * message */ orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true, - (NULL == recv_msg) ? "NO MSG" : recv_msg); + (0 == strlen(recv_msg)) ? "NO MSG" : recv_msg); ORTE_ACTIVATE_JOB_STATE(NULL, ORTE_JOB_STATE_ALLOC_FAILED); return; } @@ -789,6 +791,7 @@ static void recv_data(int fd, short args, void *cbdata) if (NULL == jtrk) { orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true, "NO JOB TRACKER"); ORTE_ACTIVATE_JOB_STATE(NULL, ORTE_JOB_STATE_ALLOC_FAILED); + opal_argv_free(alloc); return; } @@ -809,6 +812,7 @@ static void recv_data(int fd, short args, void *cbdata) if (idx < 0 || NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, idx))) { orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true, jtrk->cmd); ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOC_FAILED); + opal_argv_free(alloc); return; } /* track the Slurm jobid */ @@ -824,6 +828,7 @@ static void recv_data(int fd, short args, void *cbdata) if (ORTE_SUCCESS != (rc = orte_ras_slurm_discover(nodelist, tpn, &ndtmp))) { ORTE_ERROR_LOG(rc); ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOC_FAILED); + opal_argv_free(alloc); return; } /* transfer the discovered nodes to our node list, and construct