Commit ed39c901 authored by Rob Latham's avatar Rob Latham
Browse files

make ADIOI_Shfp_fname report errors



Right now there's only one error condition: file name too long.  This
change checks return codes of ADIOI_Strncpy and informs caller.
Otherwise, really long names result in buffer overruns.

See #2212
Signed-off-by: Kenneth Raffenetti's avatarKen Raffenetti <raffenet@mcs.anl.gov>
parent bb1c9db6
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
file pointer functions are used and is deleted when the real file pointer functions are used and is deleted when the real
file is closed. */ file is closed. */
void ADIOI_Shfp_fname(ADIO_File fd, int rank) void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code)
{ {
int i; int i;
int len; int len;
...@@ -40,7 +40,11 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank) ...@@ -40,7 +40,11 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank)
i = rand(); i = rand();
pid = (int)getpid(); pid = (int)getpid();
ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, 256); if (ADIOI_Strncpy(fd->shared_fp_fname, fd->filename, 256)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
}
#ifdef ROMIO_NTFS #ifdef ROMIO_NTFS
slash = strrchr(fd->filename, '\\'); slash = strrchr(fd->filename, '\\');
...@@ -48,8 +52,16 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank) ...@@ -48,8 +52,16 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank)
slash = strrchr(fd->filename, '/'); slash = strrchr(fd->filename, '/');
#endif #endif
if (!slash) { if (!slash) {
ADIOI_Strncpy(fd->shared_fp_fname, ".", 2); if (ADIOI_Strncpy(fd->shared_fp_fname, ".", 2)) {
ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, 255); *error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
}
if (ADIOI_Strncpy(fd->shared_fp_fname + 1, fd->filename, 255)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
}
} }
else { else {
ptr = slash; ptr = slash;
...@@ -58,13 +70,22 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank) ...@@ -58,13 +70,22 @@ void ADIOI_Shfp_fname(ADIO_File fd, int rank)
#else #else
slash = strrchr(fd->shared_fp_fname, '/'); slash = strrchr(fd->shared_fp_fname, '/');
#endif #endif
ADIOI_Strncpy(slash + 1, ".", 2); if (ADIOI_Strncpy(slash + 1, ".", 2)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
fd->filename, ENAMETOOLONG);
return;
}
/* ok to cast: file names bounded by PATH_MAX and NAME_MAX */ /* ok to cast: file names bounded by PATH_MAX and NAME_MAX */
len = (int) (256 - (slash+2 - fd->shared_fp_fname)); len = (int) (256 - (slash+2 - fd->shared_fp_fname));
ADIOI_Strncpy(slash + 2, ptr + 1, len); if (ADIOI_Strncpy(slash + 2, ptr + 1, len)) {
*error_code = ADIOI_Err_create_code("ADIOI_Shfp_fname",
ptr + 1, ENAMETOOLONG);
return;
}
} }
ADIOI_Snprintf(tmp, 128, ".shfp.%d.%d", pid, i); ADIOI_Snprintf(tmp, 128, ".shfp.%d.%d", pid, i);
/* ADIOI_Strnapp will return non-zero if truncated. That's ok */
ADIOI_Strnapp(fd->shared_fp_fname, tmp, 256); ADIOI_Strnapp(fd->shared_fp_fname, tmp, 256);
len = (int)strlen(fd->shared_fp_fname); len = (int)strlen(fd->shared_fp_fname);
......
...@@ -691,7 +691,7 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset, ...@@ -691,7 +691,7 @@ ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset,
void ADIOI_GEN_Resize(ADIO_File fd, ADIO_Offset size, int *error_code); void ADIOI_GEN_Resize(ADIO_File fd, ADIO_Offset size, int *error_code);
void ADIOI_GEN_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code); void ADIOI_GEN_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
void ADIOI_GEN_Close(ADIO_File fd, int *error_code); void ADIOI_GEN_Close(ADIO_File fd, int *error_code);
void ADIOI_Shfp_fname(ADIO_File fd, int rank); void ADIOI_Shfp_fname(ADIO_File fd, int rank, int *error_code);
void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset size, int *error_code); void ADIOI_GEN_Prealloc(ADIO_File fd, ADIO_Offset size, int *error_code);
int ADIOI_Error(ADIO_File fd, int error_code, char *string); int ADIOI_Error(ADIO_File fd, int error_code, char *string);
int MPIR_Err_setmsg( int, int, const char *, const char *, const char *, ... ); int MPIR_Err_setmsg( int, int, const char *, const char *, const char *, ... );
......
...@@ -179,7 +179,9 @@ int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode, ...@@ -179,7 +179,9 @@ int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode,
if ((error_code == MPI_SUCCESS) && if ((error_code == MPI_SUCCESS) &&
ADIO_Feature((*fh), ADIO_SHARED_FP)) { ADIO_Feature((*fh), ADIO_SHARED_FP)) {
MPI_Comm_rank(dupcomm, &rank); MPI_Comm_rank(dupcomm, &rank);
ADIOI_Shfp_fname(*fh, rank); ADIOI_Shfp_fname(*fh, rank, &error_code);
if (error_code != MPI_SUCCESS)
goto fn_fail;
/* if MPI_MODE_APPEND, set the shared file pointer to end of file. /* if MPI_MODE_APPEND, set the shared file pointer to end of file.
indiv. file pointer already set to end of file in ADIO_Open. indiv. file pointer already set to end of file in ADIO_Open.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment