[mpich-commits] [mpich] MPICH primary repository branch, master, updated. v3.2a2-136-g7dfe284

Service Account noreply at mpich.org
Thu Feb 5 16:31:46 CST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "MPICH primary repository".

The branch, master has been updated
       via  7dfe284051cacc8ef79f15e0c01c81b28f9fe78e (commit)
      from  b0dcf8cde20879b39ae1edfe1deb544f70c06147 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.mpich.org/mpich.git/commitdiff/7dfe284051cacc8ef79f15e0c01c81b28f9fe78e

commit 7dfe284051cacc8ef79f15e0c01c81b28f9fe78e
Author: Rajeev Thakur <thakur at mcs.anl.gov>
Date:   Tue Feb 3 19:54:50 2015 -0600

    Fix MPI_Info_get to pass valuelen+1 to MPIU_Strncpy and check return
    code of MPIU_Strncpy. Added test program.
    Closes #2225
    
    Signed-off-by: William Gropp <wgropp at illinois.edu>

diff --git a/src/include/mpiimpl.h b/src/include/mpiimpl.h
index 4204466..cc1a457 100644
--- a/src/include/mpiimpl.h
+++ b/src/include/mpiimpl.h
@@ -4418,7 +4418,7 @@ int MPIR_Cart_map_impl(const MPID_Comm *comm_ptr, int ndims, const int dims[],
                        const int periodic[], int *newrank);
 int MPIR_Close_port_impl(const char *port_name);
 int MPIR_Open_port_impl(MPID_Info *info_ptr, char *port_name);
-void MPIR_Info_get_impl(MPID_Info *info_ptr, const char *key, int valuelen, char *value, int *flag);
+int MPIR_Info_get_impl(MPID_Info *info_ptr, const char *key, int valuelen, char *value, int *flag);
 void MPIR_Info_get_nkeys_impl(MPID_Info *info_ptr, int *nkeys);
 int MPIR_Info_get_nthkey_impl(MPID_Info *info, int n, char *key);
 void MPIR_Info_get_valuelen_impl(MPID_Info *info_ptr, const char *key, int *valuelen, int *flag);
diff --git a/src/mpi/info/info_get.c b/src/mpi/info/info_get.c
index 690c38a..cae3f46 100644
--- a/src/mpi/info/info_get.c
+++ b/src/mpi/info/info_get.c
@@ -29,28 +29,35 @@ int MPI_Info_get(MPI_Info info, const char *key, int valuelen, char *value, int
 #define FUNCNAME MPIR_Info_get_impl
 #undef FCNAME
 #define FCNAME MPIU_QUOTE(FUNCNAME)
-void MPIR_Info_get_impl(MPID_Info *info_ptr, const char *key, int valuelen, char *value, int *flag)
+int MPIR_Info_get_impl(MPID_Info *info_ptr, const char *key, int valuelen, char *value, int *flag)
 {
     MPID_Info *curr_ptr;
+    int err=0, mpi_errno=0;
+
     curr_ptr = info_ptr->next;
     *flag = 0;
 
     while (curr_ptr) {
         if (!strncmp(curr_ptr->key, key, MPI_MAX_INFO_KEY)) {
-            MPIU_Strncpy(value, curr_ptr->value, valuelen);
-            /* The following is problematic - if the user passes the
-               declared length, then this will access memory one
-               passed that point */
-            /* FIXME: The real fix is to change MPIU_Strncpy to
-               set the null at the end (always!) and return an error
-               if it had to truncate the result. */
-            /* value[valuelen] = '\0'; */
+            err = MPIU_Strncpy(value, curr_ptr->value, valuelen+1);
+            /* +1 because the MPI Standard says "In C, valuelen
+             * (passed to MPI_Info_get) should be one less than the
+             * amount of allocated space to allow for the null
+             * terminator*/
             *flag = 1;
             break;
         }
         curr_ptr = curr_ptr->next;
     }
-    return;
+
+    /* --BEGIN ERROR HANDLING-- */
+    if (err != 0)
+    {
+        mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, FCNAME, __LINE__, MPI_ERR_INFO_VALUE, "**infovallong", NULL);
+    }
+    /* --END ERROR HANDLING-- */
+
+    return mpi_errno;
 }
 
 #endif
@@ -61,7 +68,7 @@ void MPIR_Info_get_impl(MPID_Info *info_ptr, const char *key, int valuelen, char
 Input Parameters:
 + info - info object (handle)
 . key - key (string)
-- valuelen - length of value argument (integer)
+- valuelen - length of value argument, not including null terminator (integer)
 
 Output Parameters:
 + value - value (string)
@@ -139,8 +146,9 @@ int MPI_Info_get(MPI_Info info, const char *key, int valuelen, char *value,
 #   endif /* HAVE_ERROR_CHECKING */
 
     /* ... body of routine ...  */
-    MPIR_Info_get_impl(info_ptr, key, valuelen, value, flag);
+    mpi_errno = MPIR_Info_get_impl(info_ptr, key, valuelen, value, flag);
     /* ... end of body of routine ... */
+    if (mpi_errno) goto fn_fail;
 
 #ifdef HAVE_ERROR_CHECKING
   fn_exit:
diff --git a/test/mpi/info/Makefile.am b/test/mpi/info/Makefile.am
index 956fa90..1bc23a8 100644
--- a/test/mpi/info/Makefile.am
+++ b/test/mpi/info/Makefile.am
@@ -20,4 +20,5 @@ noinst_PROGRAMS = \
     infomany      \
     infomany2     \
     infotest      \
+    infoget      \
     infoenv
diff --git a/test/mpi/info/infoget.c b/test/mpi/info/infoget.c
new file mode 100644
index 0000000..cdc0f1d
--- /dev/null
+++ b/test/mpi/info/infoget.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2001 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+/* Test code provided by Hajime Fujita. See Trac ticket #2225. */
+
+#include "mpi.h"
+#include <stdio.h>
+#include "mpitest.h"
+#include <string.h>
+
+int main(int argc, char *argv[])
+{
+    MPI_Info info;
+    const char *key = "key", *val = "val";
+    char buff[3 + 1]; /* strlen("val") + 1 */
+    int flag, errs=0;
+
+    MTest_Init(&argc, &argv);
+
+    MPI_Info_create(&info);
+    MPI_Info_set(info, key, val);
+    MPI_Info_get(info, key, sizeof(buff)-1, buff, &flag);
+    if (flag) {
+        if (strncmp(buff, val, sizeof(buff)-1) != 0) {
+            errs++;
+            printf("returned value is %s, should be %s\n", buff, val);
+        }
+    }
+    else {
+        errs++;
+        printf("key not found\n");
+    }
+    MPI_Info_free(&info);
+
+    MTest_Finalize(errs);
+    MPI_Finalize();
+
+    return 0;
+}
diff --git a/test/mpi/info/testlist b/test/mpi/info/testlist
index 724a6a2..b174c00 100644
--- a/test/mpi/info/testlist
+++ b/test/mpi/info/testlist
@@ -5,4 +5,5 @@ infoorder 1
 infomany 1
 infomany2 1
 infotest 1
+infoget 1
 infoenv 1 mpiversion=3.0

-----------------------------------------------------------------------

Summary of changes:
 src/include/mpiimpl.h     |    2 +-
 src/mpi/info/info_get.c   |   32 ++++++++++++++++++++------------
 test/mpi/info/Makefile.am |    1 +
 test/mpi/info/infoget.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 test/mpi/info/testlist    |    1 +
 5 files changed, 65 insertions(+), 13 deletions(-)
 create mode 100644 test/mpi/info/infoget.c


hooks/post-receive
-- 
MPICH primary repository


More information about the commits mailing list