Fix CID 968581: ensure that the string read from the socket is always
authorjsquyres
Thu Mar 21 16:05:50 2013 +0000 (2 months ago)
changeset 21515d738e2d8135c
parent 21514 0731cae33eef
child 21518 89648481c1c4
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...).
orte/mca/ras/slurm/ras_slurm_module.c
     1.1 --- a/orte/mca/ras/slurm/ras_slurm_module.c	Thu Mar 21 12:55:41 2013 +0000
     1.2 +++ b/orte/mca/ras/slurm/ras_slurm_module.c	Thu Mar 21 16:05:50 2013 +0000
     1.3 @@ -35,6 +35,7 @@
     1.4  #endif
     1.5  #include <fcntl.h>
     1.6  #include <stdlib.h>
     1.7 +#include <string.h>
     1.8  
     1.9  #include "opal/util/argv.h"
    1.10  #include "opal/util/net.h"
    1.11 @@ -751,7 +752,8 @@
    1.12      /* read the data from the socket and put it in the
    1.13       * nodes field of op
    1.14       */
    1.15 -    nbytes = read(fd, recv_msg, 8192);
    1.16 +    memset(recv_msg, 0, sizeof(recv_msg));
    1.17 +    nbytes = read(fd, recv_msg, sizeof(recv_msg) - 1);
    1.18  
    1.19      opal_output_verbose(2, orte_ras_base.ras_output,
    1.20                          "%s ras:slurm: dynamic allocation msg: %s",
    1.21 @@ -763,7 +765,7 @@
    1.22           * message
    1.23           */
    1.24          orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true,
    1.25 -                       (NULL == recv_msg) ? "NO MSG" : recv_msg);
    1.26 +                       (0 == strlen(recv_msg)) ? "NO MSG" : recv_msg);
    1.27          ORTE_ACTIVATE_JOB_STATE(NULL, ORTE_JOB_STATE_ALLOC_FAILED);
    1.28          return;
    1.29      }
    1.30 @@ -789,6 +791,7 @@
    1.31      if (NULL == jtrk) {
    1.32          orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true, "NO JOB TRACKER");
    1.33          ORTE_ACTIVATE_JOB_STATE(NULL, ORTE_JOB_STATE_ALLOC_FAILED);
    1.34 +        opal_argv_free(alloc);
    1.35          return;
    1.36      }
    1.37  
    1.38 @@ -809,6 +812,7 @@
    1.39          if (idx < 0 || NULL == (app = (orte_app_context_t*)opal_pointer_array_get_item(jdata->apps, idx))) {
    1.40              orte_show_help("help-ras-slurm.txt", "slurm-dyn-alloc-failed", true, jtrk->cmd);
    1.41              ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOC_FAILED);
    1.42 +            opal_argv_free(alloc);
    1.43              return;
    1.44          }
    1.45          /* track the Slurm jobid */
    1.46 @@ -824,6 +828,7 @@
    1.47          if (ORTE_SUCCESS != (rc = orte_ras_slurm_discover(nodelist, tpn, &ndtmp))) {
    1.48              ORTE_ERROR_LOG(rc);
    1.49              ORTE_ACTIVATE_JOB_STATE(jdata, ORTE_JOB_STATE_ALLOC_FAILED);
    1.50 +            opal_argv_free(alloc);
    1.51              return;
    1.52          }
    1.53          /* transfer the discovered nodes to our node list, and construct